Skip to content

Commit 1407659

Browse files
hanwengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eff5832 commit 1407659

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

reftable/readwrite_test.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,29 @@ static void test_write_empty_table(void)
667667
strbuf_release(&buf);
668668
}
669669

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+
670693
static void test_write_key_order(void)
671694
{
672695
struct reftable_write_options opts = { 0 };
@@ -746,6 +769,7 @@ int readwrite_test_main(int argc, const char *argv[])
746769
RUN_TEST(test_table_read_write_seek_index);
747770
RUN_TEST(test_table_refs_for_no_index);
748771
RUN_TEST(test_table_refs_for_obj_index);
772+
RUN_TEST(test_write_empty_key);
749773
RUN_TEST(test_write_empty_table);
750774
RUN_TEST(test_log_overflow);
751775
return 0;

0 commit comments

Comments
 (0)