summaryrefslogtreecommitdiff
path: root/tests/test-repo.c
diff options
context:
space:
mode:
authorUmang Jain <umang@endlessm.com>2018-08-31 20:20:23 +0530
committerAtomic Bot <atomic-devel@projectatomic.io>2018-09-04 21:31:34 +0000
commita70d2f67310bd869c6a40c4013dc51a3e2f2d2a8 (patch)
tree47bd9920069b9a6c1d87f39623a9af2905b59df5 /tests/test-repo.c
parent68420f70bbb288cbd4424413f86f6cfecc06d7b1 (diff)
downloadostree-a70d2f67310bd869c6a40c4013dc51a3e2f2d2a8.tar.gz
Add tests for ostree_repo_get_min_free_space_bytes
https://phabricator.endlessm.com/T23694 Closes: #1715 Approved by: cgwalters
Diffstat (limited to 'tests/test-repo.c')
-rw-r--r--tests/test-repo.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test-repo.c b/tests/test-repo.c
index edccef59..c56f60c5 100644
--- a/tests/test-repo.c
+++ b/tests/test-repo.c
@@ -151,6 +151,57 @@ test_repo_equal (Fixture *fixture,
g_assert_false (ostree_repo_equal (closed_repo, closed_repo));
}
+static void
+test_repo_get_min_free_space (Fixture *fixture,
+ gconstpointer test_data)
+{
+ g_autoptr (GKeyFile) config = NULL;
+ g_autoptr(GError) error = NULL;
+ typedef struct
+ {
+ const char *val;
+ gboolean should_succeed;
+ } min_free_space_value;
+
+ g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd, ".",
+ OSTREE_REPO_MODE_ARCHIVE,
+ NULL,
+ NULL, &error);
+ g_assert_no_error (error);
+
+ min_free_space_value values_to_test[] = {
+ {"500MB", TRUE },
+ { "0MB", TRUE },
+ { "17179869185GB", FALSE }, /* Overflow parameter: bytes > G_MAXUINT64 */
+ { NULL, FALSE }
+ };
+
+ config = ostree_repo_copy_config (repo);
+
+ for (guint i = 0; values_to_test[i].val != NULL; i++)
+ {
+ g_key_file_remove_key (config, "core", "min-free-space-size", NULL);
+ g_key_file_set_string (config, "core", "min-free-space-size", values_to_test[i].val);
+
+ ostree_repo_write_config (repo, config, &error);
+ g_assert_no_error (error);
+ ostree_repo_reload_config (repo, NULL, &error);
+ g_assert_no_error (error);
+
+ ostree_repo_prepare_transaction (repo, FALSE, NULL, &error);
+ if (values_to_test[i].should_succeed)
+ g_assert_no_error (error);
+ else
+ continue;
+
+ ostree_repo_get_min_free_space_bytes (repo);
+ g_assert_no_error (error);
+
+ ostree_repo_commit_transaction (repo, NULL, NULL, &error);
+ g_assert_no_error (error);
+ }
+}
+
int
main (int argc,
char **argv)
@@ -164,6 +215,9 @@ main (int argc,
test_repo_hash_closed, teardown);
g_test_add ("/repo/equal", Fixture, NULL, setup,
test_repo_equal, teardown);
+ g_test_add ("/repo/get_min_free_space", Fixture, NULL, setup,
+ test_repo_get_min_free_space, teardown);
+
return g_test_run ();
}