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"
15 #include "reftable-error.h"
16 #include "reftable-writer.h"
19 #include "test_framework.h"
20 #include "reftable-tests.h"
28 static void test_conflict(void)
30 struct reftable_write_options opts
= { 0 };
31 struct strbuf buf
= STRBUF_INIT
;
32 struct reftable_writer
*w
=
33 reftable_new_writer(&strbuf_add_void
, &buf
, &opts
);
34 struct reftable_ref_record rec
= {
36 .value_type
= REFTABLE_REF_SYMREF
,
37 .value
.symref
= "destination", /* make sure it's not a symref.
43 struct reftable_block_source source
= { NULL
};
44 struct reftable_reader
*rd
= NULL
;
45 struct reftable_table tab
= { NULL
};
46 struct testcase cases
[] = {
47 { "a/b/c", NULL
, REFTABLE_NAME_CONFLICT
},
49 { "a", NULL
, REFTABLE_NAME_CONFLICT
},
52 { "p/", NULL
, REFTABLE_REFNAME_ERROR
},
53 { "p//q", NULL
, REFTABLE_REFNAME_ERROR
},
54 { "p/./q", NULL
, REFTABLE_REFNAME_ERROR
},
55 { "p/../q", NULL
, REFTABLE_REFNAME_ERROR
},
57 { "a/b/c", "a/b", 0 },
60 reftable_writer_set_limits(w
, 1, 1);
62 err
= reftable_writer_add_ref(w
, &rec
);
65 err
= reftable_writer_close(w
);
67 reftable_writer_free(w
);
69 block_source_from_strbuf(&source
, &buf
);
70 err
= reftable_new_reader(&rd
, &source
, "filename");
73 reftable_table_from_reader(&tab
, rd
);
75 for (i
= 0; i
< ARRAY_SIZE(cases
); i
++) {
76 struct modification mod
= {
81 mod
.add
= &cases
[i
].add
;
85 mod
.del
= &cases
[i
].del
;
89 err
= modification_validate(&mod
);
90 EXPECT(err
== cases
[i
].error_code
);
93 reftable_reader_free(rd
);
97 int refname_test_main(int argc
, const char *argv
[])
99 RUN_TEST(test_conflict
);