tests: Add a simple test-sysroot.js that covers OSTree.Sysroot

This will be more interesting as a test case user of the API.
This commit is contained in:
Colin Walters 2013-10-02 19:47:38 -04:00
parent f9379b0ce3
commit 650aab7628
2 changed files with 58 additions and 4 deletions

View File

@ -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

53
tests/test-sysroot.js Normal file
View File

@ -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);