t-reftable-record: add comparison tests for index records

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>

Chandra Pratap committed Jul 2, 2024 at 12:52 UTC 85ca39e79b3fc3baed8ae218ac52af953121977a
1 file changed +38
t/unit-tests/t-reftable-record.c
+38
@@ -357,6 +357,43 @@ static void t_reftable_obj_record_roundtrip(void)
357 strbuf_release(&scratch);
358 }
359
360 +static void t_reftable_index_record_comparison(void)
361 +{
362 + struct reftable_record in[3] = {
363 + {
364 + .type = BLOCK_TYPE_INDEX,
365 + .u.idx.offset = 22,
366 + .u.idx.last_key = STRBUF_INIT,
367 + },
368 + {
369 + .type = BLOCK_TYPE_INDEX,
370 + .u.idx.offset = 32,
371 + .u.idx.last_key = STRBUF_INIT,
372 + },
373 + {
374 + .type = BLOCK_TYPE_INDEX,
375 + .u.idx.offset = 32,
376 + .u.idx.last_key = STRBUF_INIT,
377 + },
378 + };
379 + strbuf_addstr(&in[0].u.idx.last_key, "refs/heads/master");
380 + strbuf_addstr(&in[1].u.idx.last_key, "refs/heads/master");
381 + strbuf_addstr(&in[2].u.idx.last_key, "refs/heads/branch");
382 +
383 + check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
384 + check(!reftable_record_cmp(&in[0], &in[1]));
385 +
386 + check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
387 + check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
388 +
389 + in[1].u.idx.offset = in[0].u.idx.offset;
390 + check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
391 + check(!reftable_record_cmp(&in[0], &in[1]));
392 +
393 + for (size_t i = 0; i < ARRAY_SIZE(in); i++)
394 + reftable_record_release(&in[i]);
395 +}
396 +
397 static void t_reftable_index_record_roundtrip(void)
398 {
399 struct reftable_record in = {
@@ -405,6 +442,7 @@ int cmd_main(int argc, const char *argv[])
442 {
443 TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
444 TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
445 + TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
446 TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
447 TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
448 TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");