]> git.proxmox.com Git - libgit2.git/blob - tests/config/readonly.c
5d544b8cb4a08bb9bea67ce4ff1893d58f30c169
[libgit2.git] / tests / config / readonly.c
1 #include "clar_libgit2.h"
2 #include "config_backend.h"
3 #include "config.h"
4 #include "path.h"
5
6 static git_config *cfg;
7
8 void test_config_readonly__initialize(void)
9 {
10 cl_git_pass(git_config_new(&cfg));
11 }
12
13 void test_config_readonly__cleanup(void)
14 {
15 git_config_free(cfg);
16 cfg = NULL;
17 }
18
19 void test_config_readonly__writing_to_readonly_fails(void)
20 {
21 git_config_backend *backend;
22
23 cl_git_pass(git_config_backend_from_file(&backend, "global"));
24 backend->readonly = 1;
25 cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
26
27 cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz"));
28 cl_assert(!git_path_exists("global"));
29 }
30
31 void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
32 {
33 git_config_backend *backend;
34
35 cl_git_pass(git_config_backend_from_file(&backend, "global"));
36 backend->readonly = 1;
37 cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
38
39 cl_git_pass(git_config_backend_from_file(&backend, "local"));
40 cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
41
42 cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
43
44 cl_assert(git_path_exists("local"));
45 cl_assert(!git_path_exists("global"));
46 cl_git_pass(p_unlink("local"));
47 }
48
49 void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void)
50 {
51 git_config_backend *backend;
52
53 cl_git_pass(git_config_backend_from_file(&backend, "local"));
54 backend->readonly = 1;
55 cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
56
57 cl_git_pass(git_config_backend_from_file(&backend, "global"));
58 cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
59
60 cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
61
62 cl_assert(!git_path_exists("local"));
63 cl_assert(git_path_exists("global"));
64 cl_git_pass(p_unlink("global"));
65 }