reftable: add a test that verifies that writing empty keys fails
Empty keys can only be written as ref records with empty names. The log record has a logical timestamp in the key, so the key is never empty. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Han-Wen Nienhuys committed
Feb 21, 2022 at 18:46 UTC
140765911050d62a23503972ef6513ef18252ad3
1 file changed
+24
reftable/readwrite_test.c
+24
@@ -667,6 +667,29 @@ static void test_write_empty_table(void)
667
strbuf_release(&buf);
668
}
669
670
+static void test_write_empty_key(void)
671
+{
672
+ struct reftable_write_options opts = { 0 };
673
+ struct strbuf buf = STRBUF_INIT;
674
+ struct reftable_writer *w =
675
+ reftable_new_writer(&strbuf_add_void, &buf, &opts);
676
+ struct reftable_ref_record ref = {
677
+ .refname = "",
678
+ .update_index = 1,
679
+ .value_type = REFTABLE_REF_DELETION,
680
+ };
681
+ int err;
682
+
683
+ reftable_writer_set_limits(w, 1, 1);
684
+ err = reftable_writer_add_ref(w, &ref);
685
+ EXPECT(err == REFTABLE_API_ERROR);
686
+
687
+ err = reftable_writer_close(w);
688
+ EXPECT(err == REFTABLE_EMPTY_TABLE_ERROR);
689
+ reftable_writer_free(w);
690
+ strbuf_release(&buf);
691
+}
692
+
693
static void test_write_key_order(void)
694
{
695
struct reftable_write_options opts = { 0 };
@@ -746,6 +769,7 @@ int readwrite_test_main(int argc, const char *argv[])
769
RUN_TEST(test_table_read_write_seek_index);
770
RUN_TEST(test_table_refs_for_no_index);
771
RUN_TEST(test_table_refs_for_obj_index);
772
+ RUN_TEST(test_write_empty_key);
773
RUN_TEST(test_write_empty_table);
774
RUN_TEST(test_log_overflow);
775
return 0;