Skip to content

Commit b7bbb58

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-record: add comparison tests for ref records
In the current testing setup for ref records, the comparison functions for ref records, reftable_ref_record_cmp_void() and reftable_ref_record_equal() are left untested. Add tests for the same by using the wrapper functions reftable_record_cmp() and reftable_record_equal() for reftable_ref_record_cmp_void() and reftable_ref_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 9008b8a commit b7bbb58

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ static void set_hash(uint8_t *h, int j)
6363
h[i] = (j >> i) & 0xff;
6464
}
6565

66+
static void t_reftable_ref_record_comparison(void)
67+
{
68+
struct reftable_record in[3] = {
69+
{
70+
.type = BLOCK_TYPE_REF,
71+
.u.ref.refname = (char *) "refs/heads/master",
72+
.u.ref.value_type = REFTABLE_REF_VAL1,
73+
},
74+
{
75+
.type = BLOCK_TYPE_REF,
76+
.u.ref.refname = (char *) "refs/heads/master",
77+
.u.ref.value_type = REFTABLE_REF_DELETION,
78+
},
79+
{
80+
.type = BLOCK_TYPE_REF,
81+
.u.ref.refname = (char *) "HEAD",
82+
.u.ref.value_type = REFTABLE_REF_SYMREF,
83+
.u.ref.value.symref = (char *) "refs/heads/master",
84+
},
85+
};
86+
87+
check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
88+
check(!reftable_record_cmp(&in[0], &in[1]));
89+
90+
check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
91+
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
92+
93+
in[1].u.ref.value_type = in[0].u.ref.value_type;
94+
check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
95+
check(!reftable_record_cmp(&in[0], &in[1]));
96+
}
97+
6698
static void t_reftable_ref_record_roundtrip(void)
6799
{
68100
struct strbuf scratch = STRBUF_INIT;
@@ -371,6 +403,7 @@ static void t_reftable_index_record_roundtrip(void)
371403

372404
int cmd_main(int argc, const char *argv[])
373405
{
406+
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
374407
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
375408
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
376409
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");

0 commit comments

Comments
 (0)