2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
11 #include "blocksource.h"
12 #include "constants.h"
16 #include "reftable-error.h"
17 #include "reftable-writer.h"
20 #include "test_framework.h"
21 #include "reftable-tests.h"
29 static void test_conflict(void)
31 struct reftable_write_options opts
= { 0 };
32 struct strbuf buf
= STRBUF_INIT
;
33 struct reftable_writer
*w
=
34 reftable_new_writer(&strbuf_add_void
, &buf
, &opts
);
35 struct reftable_ref_record rec
= {
37 .value_type
= REFTABLE_REF_SYMREF
,
38 .value
.symref
= "destination", /* make sure it's not a symref.
44 struct reftable_block_source source
= { NULL
};
45 struct reftable_reader
*rd
= NULL
;
46 struct reftable_table tab
= { NULL
};
47 struct testcase cases
[] = {
48 { "a/b/c", NULL
, REFTABLE_NAME_CONFLICT
},
50 { "a", NULL
, REFTABLE_NAME_CONFLICT
},
53 { "p/", NULL
, REFTABLE_REFNAME_ERROR
},
54 { "p//q", NULL
, REFTABLE_REFNAME_ERROR
},
55 { "p/./q", NULL
, REFTABLE_REFNAME_ERROR
},
56 { "p/../q", NULL
, REFTABLE_REFNAME_ERROR
},
58 { "a/b/c", "a/b", 0 },
61 reftable_writer_set_limits(w
, 1, 1);
63 err
= reftable_writer_add_ref(w
, &rec
);
66 err
= reftable_writer_close(w
);
68 reftable_writer_free(w
);
70 block_source_from_strbuf(&source
, &buf
);
71 err
= reftable_new_reader(&rd
, &source
, "filename");
74 reftable_table_from_reader(&tab
, rd
);
76 for (i
= 0; i
< ARRAY_SIZE(cases
); i
++) {
77 struct modification mod
= {
82 mod
.add
= &cases
[i
].add
;
86 mod
.del
= &cases
[i
].del
;
90 err
= modification_validate(&mod
);
91 EXPECT(err
== cases
[i
].error_code
);
94 reftable_reader_free(rd
);
98 int refname_test_main(int argc
, const char *argv
[])
100 RUN_TEST(test_conflict
);