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 <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
b7bbb58c14ba92dbfaeb4e995a61b633a8754194
1 file changed
+33
t/unit-tests/t-reftable-record.c
+33
@@ -63,6 +63,38 @@ static void set_hash(uint8_t *h, int j)
63
h[i] = (j >> i) & 0xff;
64
}
65
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
+
98
static void t_reftable_ref_record_roundtrip(void)
99
{
100
struct strbuf scratch = STRBUF_INIT;
@@ -371,6 +403,7 @@ static void t_reftable_index_record_roundtrip(void)
403
404
int cmd_main(int argc, const char *argv[])
405
{
406
+ TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
407
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
408
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
409
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");