[ostree] tests: Add a gjs-based test



commit 58a8d6d6efca9cd7469ac4623bd0d8d69052e11e
Author: Colin Walters <walters verbum org>
Date:   Wed Sep 18 12:01:46 2013 -0400

    tests: Add a gjs-based test
    
    This covers introspection, and in general is a much better way to get
    API coverage tests.

 Makefile-tests.am  |   12 ++++++++++++
 configure.ac       |   10 ++++++++++
 tests/test-core.js |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-tests.am b/Makefile-tests.am
index 144dac9..82382da 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -47,7 +47,19 @@ insttest_DATA = tests/archive-test.sh \
         echo 'Output=TAP' >> $  tmp; \
         mv $  tmp $@)
 
+%.test: tests/%.js Makefile
+       $(AM_V_GEN) (echo '[Test]' > $  tmp; \
+        echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $  tmp; \
+        echo 'Type=session' >> $  tmp; \
+        mv $  tmp $@)
+
 testmetadir = $(datadir)/installed-tests/$(PACKAGE)
 testmeta_DATA = $(testfiles:=.test)
 
+if BUILDOPT_GJS
+insttest_SCRIPTS += tests/test-core.js
+testmeta_DATA += test-core.test
+endif
+
+
 endif
diff --git a/configure.ac b/configure.ac
index 74df7b4..d289876 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,15 @@ AS_IF([test "x$with_dracut" = "xyes"], [
   ])
 ])
 
+dnl for tests
+AC_PATH_PROG(GJS, [gjs])
+if test -n "$GJS"; then
+  have_gjs=yes
+else
+  have_gjs=no
+fi
+AM_CONDITIONAL(BUILDOPT_GJS, test x$have_gjs = xyes)
+
 AC_CONFIG_FILES([
 Makefile
 embedded-dependencies/Makefile
@@ -146,6 +155,7 @@ echo "
     libsoup (retrieve remote HTTP repositories):  $with_soup
     libarchive (parse tar files directly):        $with_libarchive
     documentation:                                $enable_gtk_doc
+    gjs-based tests:                              $have_gjs
     dracut:                                       $with_dracut"
 AS_IF([test "x$with_dracut" = "xyes"], [
     echo "    systemd unit dir:                             $with_systemdsystemunitdir"
diff --git a/tests/test-core.js b/tests/test-core.js
new file mode 100644
index 0000000..44c5d1e
--- /dev/null
+++ b/tests/test-core.js
@@ -0,0 +1,38 @@
+#!/usr/bin/env gjs
+
+const Gio = imports.gi.Gio;
+const OSTree = imports.gi.OSTree;
+
+function assertEquals(a, b) {
+    if (a != b)
+       throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
+}
+
+let testDataDir = Gio.File.new_for_path('test-data');
+testDataDir.make_directory(null);
+testDataDir.get_child('some-file').replace_contents("hello world!", null, false, 0, null);
+
+let repoPath = Gio.File.new_for_path('repo');
+let repo = OSTree.Repo.new(repoPath);
+repo.create(OSTree.RepoMode.ARCHIVE_Z2, null);
+
+repo.open(null);
+
+assertEquals(repo.get_mode(), OSTree.RepoMode.ARCHIVE_Z2);
+
+repo.prepare_transaction(null);
+
+let mtree = OSTree.MutableTree.new();
+repo.write_directory_to_mtree(testDataDir, mtree, null, null);
+let [,dirTree] = repo.write_mtree(mtree, null);
+let [,commit] = repo.write_commit(null, 'Some subject', 'Some body', null, dirTree, null);
+print("commit => " + commit);
+
+repo.commit_transaction(null, null);
+
+let [,root,checksum] = repo.read_commit(commit, null);
+let child = root.get_child('some-file');
+let info = child.query_info("standard::name,standard::type,standard::size", 0, null);
+assertEquals(info.get_size(), 12);
+
+print("test-core complete");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]