t-reftable-record: add reftable_record_cmp() tests for log records

In the current testing setup for log records, only reftable_log_record_equal() among log record's comparison functions is tested. Modify the existing tests to exercise reftable_log_record_cmp_void() (using the wrapper function reftable_record_cmp()) alongside reftable_log_record_equal(). Note that to achieve this, we'll need to replace instances of reftable_log_record_equal() with the wrapper function reftable_record_equal(). Rename the now modified test to reflect its nature of exercising all comparison operations, not just equality. 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>

Chandra Pratap committed Jul 2, 2024 at 12:52 UTC 9008b8a6e8c0c96bbe9bb2ebb4842c89eca39f6d
1 file changed +25 -13
t/unit-tests/t-reftable-record.c
+25 -13
@@ -120,24 +120,36 @@ static void t_reftable_ref_record_roundtrip(void)
120 strbuf_release(&scratch);
121 }
122
123 -static void t_reftable_log_record_equal(void)
123 +static void t_reftable_log_record_comparison(void)
124 {
125 - struct reftable_log_record in[2] = {
125 + struct reftable_record in[3] = {
126 {
127 - .refname = xstrdup("refs/heads/master"),
128 - .update_index = 42,
127 + .type = BLOCK_TYPE_LOG,
128 + .u.log.refname = (char *) "refs/heads/master",
129 + .u.log.update_index = 42,
130 },
131 {
131 - .refname = xstrdup("refs/heads/master"),
132 - .update_index = 22,
133 - }
132 + .type = BLOCK_TYPE_LOG,
133 + .u.log.refname = (char *) "refs/heads/master",
134 + .u.log.update_index = 22,
135 + },
136 + {
137 + .type = BLOCK_TYPE_LOG,
138 + .u.log.refname = (char *) "refs/heads/main",
139 + .u.log.update_index = 22,
140 + },
141 };
142
136 - check(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
137 - in[1].update_index = in[0].update_index;
138 - check(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
139 - reftable_log_record_release(&in[0]);
140 - reftable_log_record_release(&in[1]);
143 + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
144 + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
145 + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
146 + /* comparison should be reversed for equal keys, because
147 + * comparison is now performed on the basis of update indices */
148 + check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
149 +
150 + in[1].u.log.update_index = in[0].u.log.update_index;
151 + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
152 + check(!reftable_record_cmp(&in[0], &in[1]));
153 }
154
155 static void t_reftable_log_record_roundtrip(void)
@@ -359,7 +371,7 @@ static void t_reftable_index_record_roundtrip(void)
371
372 int cmd_main(int argc, const char *argv[])
373 {
362 - TEST(t_reftable_log_record_equal(), "reftable_log_record_equal works");
374 + TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
375 TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
376 TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
377 TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");