Add tests for ostree_repo_get_min_free_space_bytes
authorUmang Jain <umang@endlessm.com>
Fri, 31 Aug 2018 14:50:23 +0000 (20:20 +0530)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 4 Sep 2018 21:31:34 +0000 (21:31 +0000)
https://phabricator.endlessm.com/T23694

Closes: #1715
Approved by: cgwalters

src/libostree/libostree-devel.sym
tests/test-repo.c

index 0bdade759c40019a561b425baf35337affe888db..0ba9a21581e136f1f9c789ee69abc2ad96790141 100644 (file)
@@ -19,7 +19,7 @@
 
 /* Add new symbols here.  Release commits should copy this section into -released.sym. */
 LIBOSTREE_2018.9 {
-ostree_repo_get_min_free_space_bytes;
+  ostree_repo_get_min_free_space_bytes;
 } LIBOSTREE_2018.7;
 
 /* Stub section for the stable release *after* this development one; don't
index edccef595edbafc2108f9f548d056a494fb1bf58..c56f60c5eee08c3aa985bcf8fe14f6a906e78bb5 100644 (file)
@@ -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 ();
 }