summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-10-02 19:47:38 -0400
committerColin Walters <walters@verbum.org>2013-10-02 20:18:06 -0400
commit650aab7628168e2a08b5342ff274ea62fac40490 (patch)
treecf8b2b5e4b3180c0b95c17b9f30609f244a0afd8
parentf9379b0ce3ff26c66c090f586efa644cbf47609f (diff)
downloadostree-650aab7628168e2a08b5342ff274ea62fac40490.tar.gz
tests: Add a simple test-sysroot.js that covers OSTree.Sysroot
This will be more interesting as a test case user of the API.
-rw-r--r--Makefile-tests.am9
-rw-r--r--tests/test-sysroot.js53
2 files changed, 58 insertions, 4 deletions
diff --git a/Makefile-tests.am b/Makefile-tests.am
index c0121411..bfc84e49 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -57,7 +57,7 @@ gpginsttest_DATA = tests/gpghome/secring.gpg \
%.test: tests/%.js Makefile
$(AM_V_GEN) (echo '[Test]' > $@.tmp; \
- echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
+ echo 'Exec=env TESTDATADIR=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
echo 'Type=session' >> $@.tmp; \
mv $@.tmp $@)
@@ -65,9 +65,10 @@ testmetadir = $(datadir)/installed-tests/$(PACKAGE)
testmeta_DATA = $(testfiles:=.test)
if BUILDOPT_GJS
-insttest_SCRIPTS += tests/test-core.js
-testmeta_DATA += test-core.test
+insttest_SCRIPTS += tests/test-core.js \
+ tests/test-sysroot.js \
+ $(NULL)
+testmeta_DATA += test-core.test test-sysroot.test
endif
-
endif
diff --git a/tests/test-sysroot.js b/tests/test-sysroot.js
new file mode 100644
index 00000000..ef1f26b6
--- /dev/null
+++ b/tests/test-sysroot.js
@@ -0,0 +1,53 @@
+#!/usr/bin/env gjs
+//
+// Copyright (C) 2013 Colin Walters <walters@verbum.org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+const GLib = imports.gi.GLib;
+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));
+}
+
+function libtestExec(shellCode) {
+ let testdatadir = GLib.getenv("TESTDATADIR");
+ let libtestPath = GLib.build_filenamev([testdatadir, 'libtest.sh'])
+ let cmdline = 'bash -c ' + GLib.shell_quote('. ' + GLib.shell_quote(libtestPath) + '; ' + shellCode);
+ print("shellcode=" +cmdline);
+ let [,stdout,stderr,estatus] = GLib.spawn_command_line_sync(cmdline);
+ print(stderr);
+ GLib.spawn_check_exit_status(estatus);
+}
+
+libtestExec('setup_os_repository archive-z2 syslinux');
+
+let upstreamRepo = OSTree.Repo.new(Gio.File.new_for_path('testos-repo'));
+upstreamRepo.open(null);
+
+let [,rev] = upstreamRepo.resolve_rev('testos/buildmaster/x86_64-runtime', false);
+
+print("testos => " + rev);
+
+let sysroot = OSTree.Sysroot.new(Gio.File.new_for_path('sysroot'));
+sysroot.load(null);
+let deployments = sysroot.get_deployments();
+assertEquals(deployments.length, 0);
+