Blame tests/test-core.js

Packit Service 2a3f3d
#!/usr/bin/env gjs
Packit Service 2a3f3d
//
Packit Service 2a3f3d
// Copyright (C) 2013 Colin Walters <walters@verbum.org>
Packit Service 2a3f3d
//
Packit Service 2a3f3d
// SPDX-License-Identifier: LGPL-2.0+
Packit Service 2a3f3d
//
Packit Service 2a3f3d
// This library is free software; you can redistribute it and/or
Packit Service 2a3f3d
// modify it under the terms of the GNU Lesser General Public
Packit Service 2a3f3d
// License as published by the Free Software Foundation; either
Packit Service 2a3f3d
// version 2 of the License, or (at your option) any later version.
Packit Service 2a3f3d
//
Packit Service 2a3f3d
// This library is distributed in the hope that it will be useful,
Packit Service 2a3f3d
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2a3f3d
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2a3f3d
// Lesser General Public License for more details.
Packit Service 2a3f3d
//
Packit Service 2a3f3d
// You should have received a copy of the GNU Lesser General Public
Packit Service 2a3f3d
// License along with this library; if not, write to the
Packit Service 2a3f3d
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service 2a3f3d
// Boston, MA 02111-1307, USA.
Packit Service 2a3f3d
Packit Service 2a3f3d
const Gio = imports.gi.Gio;
Packit Service 2a3f3d
const OSTree = imports.gi.OSTree;
Packit Service 2a3f3d
Packit Service 2a3f3d
function assertEquals(a, b) {
Packit Service 2a3f3d
    if (a != b)
Packit Service 2a3f3d
	throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
Packit Service 2a3f3d
}
Packit Service 2a3f3d
Packit Service 2a3f3d
print('1..1')
Packit Service 2a3f3d
Packit Service 2a3f3d
let testDataDir = Gio.File.new_for_path('test-data');
Packit Service 2a3f3d
testDataDir.make_directory(null);
Packit Service 2a3f3d
testDataDir.get_child('some-file').replace_contents("hello world!", null, false, 0, null);
Packit Service 2a3f3d
Packit Service 2a3f3d
let repoPath = Gio.File.new_for_path('repo');
Packit Service 2a3f3d
let repo = OSTree.Repo.new(repoPath);
Packit Service 2a3f3d
repo.create(OSTree.RepoMode.ARCHIVE_Z2, null);
Packit Service 2a3f3d
Packit Service 2a3f3d
repo.open(null);
Packit Service 2a3f3d
Packit Service 2a3f3d
assertEquals(repo.get_mode(), OSTree.RepoMode.ARCHIVE_Z2);
Packit Service 2a3f3d
Packit Service 2a3f3d
repo.prepare_transaction(null);
Packit Service 2a3f3d
Packit Service 2a3f3d
let mtree = OSTree.MutableTree.new();
Packit Service 2a3f3d
repo.write_directory_to_mtree(testDataDir, mtree, null, null);
Packit Service 2a3f3d
let [,dirTree] = repo.write_mtree(mtree, null);
Packit Service 2a3f3d
let [,commit] = repo.write_commit(null, 'Some subject', 'Some body', null, dirTree, null);
Packit Service 2a3f3d
print("commit => " + commit);
Packit Service 2a3f3d
Packit Service 2a3f3d
repo.commit_transaction(null, null);
Packit Service 2a3f3d
Packit Service 2a3f3d
let [,root,checksum] = repo.read_commit(commit, null);
Packit Service 2a3f3d
let child = root.get_child('some-file');
Packit Service 2a3f3d
let info = child.query_info("standard::name,standard::type,standard::size", 0, null);
Packit Service 2a3f3d
assertEquals(info.get_size(), 12);
Packit Service 2a3f3d
Packit Service 2a3f3d
// Write a ref and read it back
Packit Service 2a3f3d
repo.prepare_transaction(null);
Packit Service 2a3f3d
repo.transaction_set_refspec('someref', commit);
Packit Service 2a3f3d
repo.commit_transaction(null, null);
Packit Service 2a3f3d
let [,readCommit] = repo.resolve_rev('someref', false);
Packit Service 2a3f3d
assertEquals(readCommit, commit);
Packit Service 2a3f3d
Packit Service 2a3f3d
// Delete a ref
Packit Service 2a3f3d
repo.prepare_transaction(null);
Packit Service 2a3f3d
repo.transaction_set_refspec('someref', null);
Packit Service 2a3f3d
repo.commit_transaction(null, null);
Packit Service 2a3f3d
[,readCommit] = repo.resolve_rev('someref', true);
Packit Service 2a3f3d
assertEquals(readCommit, null);
Packit Service 2a3f3d
Packit Service 2a3f3d
print("ok test-core");