mirror of
https://git.proxmox.com/git/libgit2
synced 2025-12-25 20:38:59 +00:00
tests: config: verify functionality with read-only backends
This commit is contained in:
parent
95f29fb35b
commit
2a7086fa89
64
tests/config/readonly.c
Normal file
64
tests/config/readonly.c
Normal file
@ -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"));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user