Skip to content

Commit 85ca39e

Browse files
Chandra Pratapgitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Acked-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b7bbb58 commit 85ca39e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

t/unit-tests/t-reftable-record.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,43 @@ static void t_reftable_obj_record_roundtrip(void)
357357
strbuf_release(&scratch);
358358
}
359359

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+
360397
static void t_reftable_index_record_roundtrip(void)
361398
{
362399
struct reftable_record in = {
@@ -405,6 +442,7 @@ int cmd_main(int argc, const char *argv[])
405442
{
406443
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
407444
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");
408446
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
409447
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
410448
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");

0 commit comments

Comments
 (0)