summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-12 10:04:52 -0700
committerRussell Belfer <rb@github.com>2014-05-12 10:04:52 -0700
commitd2c4d1c63d9d5456fcf2cdcd578073d9e7dadc2a (patch)
tree70b0341e6e5d4898e8b332b658cc0fb2b29a6271 /tests
parente18d5e52e385c0cc2ad8d9d4fdd545517f170a11 (diff)
parentac99d86ba5e2a9d2332b7f82737e1231c621dc43 (diff)
downloadlibgit2-d2c4d1c63d9d5456fcf2cdcd578073d9e7dadc2a.tar.gz
Merge pull request #2188 from libgit2/cmn/config-snapshot
Configuration snapshotting
Diffstat (limited to 'tests')
-rw-r--r--tests/config/multivar.c6
-rw-r--r--tests/config/refresh.c9
-rw-r--r--tests/config/snapshot.c64
-rw-r--r--tests/config/write.c27
4 files changed, 97 insertions, 9 deletions
diff --git a/tests/config/multivar.c b/tests/config/multivar.c
index afdb1e5f4..015008992 100644
--- a/tests/config/multivar.c
+++ b/tests/config/multivar.c
@@ -231,13 +231,13 @@ void test_config_multivar__delete(void)
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
- cl_assert(n == 2);
+ cl_assert_equal_i(2, n);
cl_git_pass(git_config_delete_multivar(cfg, _name, "github"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
- cl_assert(n == 1);
+ cl_assert_equal_i(1, n);
git_config_free(cfg);
@@ -245,7 +245,7 @@ void test_config_multivar__delete(void)
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
- cl_assert(n == 1);
+ cl_assert_equal_i(1, n);
git_config_free(cfg);
}
diff --git a/tests/config/refresh.c b/tests/config/refresh.c
index 99d677f0e..08cd45b95 100644
--- a/tests/config/refresh.c
+++ b/tests/config/refresh.c
@@ -26,9 +26,6 @@ void test_config_refresh__update_value(void)
cl_git_rewritefile(TEST_FILE, "[section]\n\tvalue = 10\n\n");
- cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
- cl_assert_equal_i(1, v);
-
cl_git_pass(git_config_refresh(cfg));
cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
@@ -53,9 +50,9 @@ void test_config_refresh__delete_value(void)
cl_git_rewritefile(TEST_FILE, "[section]\n\tnewval = 10\n\n");
- cl_git_pass(git_config_get_int32(&v, cfg, "section.value"));
- cl_assert_equal_i(1, v);
- cl_git_fail(git_config_get_int32(&v, cfg, "section.newval"));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_get_int32(&v, cfg, "section.value"));
+
+ cl_git_pass(git_config_get_int32(&v, cfg, "section.newval"));
cl_git_pass(git_config_refresh(cfg));
diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c
new file mode 100644
index 000000000..c9f15921a
--- /dev/null
+++ b/tests/config/snapshot.c
@@ -0,0 +1,64 @@
+#include "clar_libgit2.h"
+
+void test_config_snapshot__create_snapshot(void)
+{
+ int32_t tmp;
+ git_config *cfg, *snapshot;
+ const char *filename = "config-ext-change";
+
+ cl_git_mkfile(filename, "[old]\nvalue = 5\n");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+
+ cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
+ cl_assert_equal_i(5, tmp);
+
+ cl_git_pass(git_config_snapshot(&snapshot, cfg));
+
+ /* Change the value on the file itself (simulate external process) */
+ cl_git_mkfile(filename, "[old]\nvalue = 56\n");
+
+ cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
+ cl_assert_equal_i(56, tmp);
+
+ cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
+ cl_assert_equal_i(5, tmp);
+
+ git_config_free(snapshot);
+ git_config_free(cfg);
+}
+
+static int count_me(const git_config_entry *entry, void *payload)
+{
+ int *n = (int *) payload;
+
+ GIT_UNUSED(entry);
+
+ (*n)++;
+
+ return 0;
+}
+
+void test_config_snapshot__multivar(void)
+{
+ int count = 0;
+ git_config *cfg, *snapshot;
+ const char *filename = "config-file";
+
+ cl_git_mkfile(filename, "[old]\nvalue = 5\nvalue = 6\n");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+ cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count));
+
+ cl_assert_equal_i(2, count);
+
+ cl_git_pass(git_config_snapshot(&snapshot, cfg));
+ git_config_free(cfg);
+
+ count = 0;
+ cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count));
+
+ cl_assert_equal_i(2, count);
+
+ git_config_free(snapshot);
+}
diff --git a/tests/config/write.c b/tests/config/write.c
index 922d75557..402be9317 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -304,3 +304,30 @@ void test_config_write__updating_a_locked_config_file_returns_ELOCKED(void)
git_config_free(cfg);
}
+void test_config_write__outside_change(void)
+{
+ int32_t tmp;
+ git_config *cfg;
+ const char *filename = "config-ext-change";
+
+ cl_git_mkfile(filename, "[old]\nvalue = 5\n");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, filename));
+
+ cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
+
+ /* Change the value on the file itself (simulate external process) */
+ cl_git_mkfile(filename, "[old]\nvalue = 6\n");
+
+ cl_git_pass(git_config_set_int32(cfg, "new.value", 7));
+
+ cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
+ cl_assert_equal_i(6, tmp);
+
+ cl_git_pass(git_config_refresh(cfg));
+
+ cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
+ cl_assert_equal_i(6, tmp);
+
+ git_config_free(cfg);
+}