Commit 835211dc by Patrick Steinhardt

tests: config: assert behaviour around includes

Add a few tests that verify some behaviour centered around includes. The
first set of tests verifies that we correctly override values depending
on the order of includes and other keys, the second set asserts that we
can correctly snapshot configuration files with includes.
parent 304e58c0
......@@ -202,3 +202,33 @@ void test_config_include__included_variables_cannot_be_modified(void)
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__variables_in_included_override_including(void)
{
int i;
cl_git_mkfile("top-level", "[foo]\nbar = 1\n[include]\npath = included");
cl_git_mkfile("included", "[foo]\nbar = 2");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
cl_assert_equal_i(i, 2);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__variables_in_including_override_included(void)
{
int i;
cl_git_mkfile("top-level", "[include]\npath = included\n[foo]\nbar = 1");
cl_git_mkfile("included", "[foo]\nbar = 2");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
cl_assert_equal_i(i, 1);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
......@@ -74,3 +74,29 @@ void test_config_snapshot__multivar(void)
cl_git_pass(p_unlink("config"));
}
void test_config_snapshot__includes(void)
{
int i;
cl_git_mkfile("including", "[include]\npath = included");
cl_git_mkfile("included", "[section]\nkey = 1\n");
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
cl_assert_equal_i(i, 1);
/* Rewrite "included" config */
cl_git_mkfile("included", "[section]\nkey = 11\n");
/* Assert that the live config changed, but snapshot remained the same */
cl_git_pass(git_config_get_int32(&i, cfg, "section.key"));
cl_assert_equal_i(i, 11);
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
cl_assert_equal_i(i, 1);
cl_git_pass(p_unlink("including"));
cl_git_pass(p_unlink("included"));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment