readonly.c 1.85 KB
Newer Older
1
#include "clar_libgit2.h"
2
#include "config_backend.h"
3
#include "config.h"
4
#include "path.h"
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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;

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 28 29 30 31 32 33 34

	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;

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 43 44 45 46 47 48 49 50 51 52

	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;

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 61 62 63 64 65

	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"));
}