]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t-reftable-record: add comparison tests for index records
authorChandra Pratap <chandrapratap3519@gmail.com>
Tue, 2 Jul 2024 07:22:17 +0000 (12:52 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jul 2024 15:12:25 +0000 (08:12 -0700)
In the current testing setup for index records, the comparison
functions for index records, reftable_index_record_cmp() and
reftable_index_record_equal() are left untested.

Add tests for the same by using the wrapper functions
reftable_record_cmp() and reftable_record_equal() for
reftable_index_record_cmp() and reftable_index_record_equal()
respectively.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Acked-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/unit-tests/t-reftable-record.c

index 99534acd17687872ace743adb6665e9695a13c21..e8db337eb82f2b7132773cec5e5f9cf3a6a8a505 100644 (file)
@@ -357,6 +357,43 @@ static void t_reftable_obj_record_roundtrip(void)
        strbuf_release(&scratch);
 }
 
+static void t_reftable_index_record_comparison(void)
+{
+       struct reftable_record in[3] = {
+               {
+                       .type = BLOCK_TYPE_INDEX,
+                       .u.idx.offset = 22,
+                       .u.idx.last_key = STRBUF_INIT,
+               },
+               {
+                       .type = BLOCK_TYPE_INDEX,
+                       .u.idx.offset = 32,
+                       .u.idx.last_key = STRBUF_INIT,
+               },
+               {
+                       .type = BLOCK_TYPE_INDEX,
+                       .u.idx.offset = 32,
+                       .u.idx.last_key = STRBUF_INIT,
+               },
+       };
+       strbuf_addstr(&in[0].u.idx.last_key, "refs/heads/master");
+       strbuf_addstr(&in[1].u.idx.last_key, "refs/heads/master");
+       strbuf_addstr(&in[2].u.idx.last_key, "refs/heads/branch");
+
+       check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+       check(!reftable_record_cmp(&in[0], &in[1]));
+
+       check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
+       check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
+
+       in[1].u.idx.offset = in[0].u.idx.offset;
+       check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+       check(!reftable_record_cmp(&in[0], &in[1]));
+
+       for (size_t i = 0; i < ARRAY_SIZE(in); i++)
+               reftable_record_release(&in[i]);
+}
+
 static void t_reftable_index_record_roundtrip(void)
 {
        struct reftable_record in = {
@@ -405,6 +442,7 @@ int cmd_main(int argc, const char *argv[])
 {
        TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
        TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
+       TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
        TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
        TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
        TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");