Skip to content

Commit 2a7086f

Browse files
committed
tests: config: verify functionality with read-only backends
1 parent 95f29fb commit 2a7086f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/config/readonly.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "clar_libgit2.h"
2+
#include "config_file.h"
3+
#include "config.h"
4+
5+
static git_config *cfg;
6+
7+
void test_config_readonly__initialize(void)
8+
{
9+
cl_git_pass(git_config_new(&cfg));
10+
}
11+
12+
void test_config_readonly__cleanup(void)
13+
{
14+
git_config_free(cfg);
15+
cfg = NULL;
16+
}
17+
18+
void test_config_readonly__writing_to_readonly_fails(void)
19+
{
20+
git_config_backend *backend;
21+
22+
cl_git_pass(git_config_file__ondisk(&backend, "global"));
23+
backend->readonly = 1;
24+
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
25+
26+
cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz"));
27+
cl_assert(!git_path_exists("global"));
28+
}
29+
30+
void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
31+
{
32+
git_config_backend *backend;
33+
34+
cl_git_pass(git_config_file__ondisk(&backend, "global"));
35+
backend->readonly = 1;
36+
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
37+
38+
cl_git_pass(git_config_file__ondisk(&backend, "local"));
39+
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0));
40+
41+
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
42+
43+
cl_assert(git_path_exists("local"));
44+
cl_assert(!git_path_exists("global"));
45+
cl_git_pass(p_unlink("local"));
46+
}
47+
48+
void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void)
49+
{
50+
git_config_backend *backend;
51+
52+
cl_git_pass(git_config_file__ondisk(&backend, "local"));
53+
backend->readonly = 1;
54+
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0));
55+
56+
cl_git_pass(git_config_file__ondisk(&backend, "global"));
57+
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0));
58+
59+
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
60+
61+
cl_assert(!git_path_exists("local"));
62+
cl_assert(git_path_exists("global"));
63+
cl_git_pass(p_unlink("global"));
64+
}

0 commit comments

Comments
 (0)