diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-04-25 13:23:04 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-04-26 09:35:11 +0200 |
| commit | 2a7086fa890a7c4876699a3b3ac1561dfd71ccf6 (patch) | |
| tree | aaf962e643c0ab2be6630635e226424a08b94353 | |
| parent | 95f29fb35b9fbc7bd98f20bd91886522ddc03f4b (diff) | |
| download | libgit2-2a7086fa890a7c4876699a3b3ac1561dfd71ccf6.tar.gz | |
tests: config: verify functionality with read-only backends
| -rw-r--r-- | tests/config/readonly.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/config/readonly.c b/tests/config/readonly.c new file mode 100644 index 000000000..f45abdd29 --- /dev/null +++ b/tests/config/readonly.c @@ -0,0 +1,64 @@ +#include "clar_libgit2.h" +#include "config_file.h" +#include "config.h" + +static git_config *cfg; + +void test_config_readonly__initialize(void) +{ + cl_git_pass(git_config_new(&cfg)); +} + +void test_config_readonly__cleanup(void) +{ + git_config_free(cfg); + cfg = NULL; +} + +void test_config_readonly__writing_to_readonly_fails(void) +{ + git_config_backend *backend; + + cl_git_pass(git_config_file__ondisk(&backend, "global")); + backend->readonly = 1; + cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0)); + + cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz")); + cl_assert(!git_path_exists("global")); +} + +void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void) +{ + git_config_backend *backend; + + cl_git_pass(git_config_file__ondisk(&backend, "global")); + backend->readonly = 1; + cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0)); + + cl_git_pass(git_config_file__ondisk(&backend, "local")); + cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0)); + + cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); + + cl_assert(git_path_exists("local")); + cl_assert(!git_path_exists("global")); + cl_git_pass(p_unlink("local")); +} + +void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void) +{ + git_config_backend *backend; + + cl_git_pass(git_config_file__ondisk(&backend, "local")); + backend->readonly = 1; + cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, 0)); + + cl_git_pass(git_config_file__ondisk(&backend, "global")); + cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, 0)); + + cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); + + cl_assert(!git_path_exists("local")); + cl_assert(git_path_exists("global")); + cl_git_pass(p_unlink("global")); +} |
