mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-06 05:31:50 +00:00
Add bundle information files under /usr/share/clear/allbundles to allow clients to perform future bundle-info operations. Write with 'pretty' indented JSON so it is grep-able and human-readable in the mean-time. Users will have to install the os-core-update-index bundle to get this functionality. Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package swupd
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestCreateFileFromPath(t *testing.T) {
|
|
resetHash()
|
|
path := "testdata/manifest.good"
|
|
expected := File{
|
|
Name: path,
|
|
Type: TypeFile,
|
|
}
|
|
|
|
var fh Hashval
|
|
var err error
|
|
fh, err = Hashcalc(expected.Name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expected.Hash = fh
|
|
|
|
m := Manifest{}
|
|
var fi os.FileInfo
|
|
if fi, err = os.Lstat(path); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = m.createFileRecord("", path, "", fi)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
newFile := m.Files[0]
|
|
if newFile.Name != expected.Name ||
|
|
newFile.Type != expected.Type ||
|
|
!HashEquals(newFile.Hash, expected.Hash) {
|
|
t.Error("created File did not match expected")
|
|
}
|
|
}
|
|
|
|
func TestAddFilesFromChroot(t *testing.T) {
|
|
rootPath := "testdata/testbundle"
|
|
m := Manifest{}
|
|
if err := m.addFilesFromChroot(rootPath, ""); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if len(m.Files) != 6 {
|
|
t.Error("incorrect number of files added from chroot")
|
|
}
|
|
}
|
|
|
|
func TestAddFilesFromChrootNotExist(t *testing.T) {
|
|
rootPath := "testdata/nowhere"
|
|
m := Manifest{}
|
|
if err := m.addFilesFromChroot(rootPath, ""); err == nil {
|
|
t.Errorf("addFilesFromChroot did not fail on missing root")
|
|
}
|
|
}
|
|
|
|
func TestExists(t *testing.T) {
|
|
if !exists("testdata/manifest.good") {
|
|
t.Error("exists() did not return true for existing file")
|
|
}
|
|
|
|
if exists("testdata/nowhere") {
|
|
t.Error("exists() returned true for non-existent file")
|
|
}
|
|
}
|