-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuilder_test.go
53 lines (41 loc) · 1.48 KB
/
builder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// rootfsbuilder - A simple tool to build Debian/Ubuntu rootfs tarballs
// Copyright (C) 2023 Hugo Melder
//
// SPDX-License-Identifier: MIT
//
package main
import (
"os"
"testing"
)
func TestCheckQemuStaticAvailability(t *testing.T) {
originalPath := os.Getenv("PATH")
defer os.Setenv("PATH", originalPath)
os.Setenv("PATH", getCwd()+"/resources/testdata/mockbin")
absolutePath, binary, err := checkQemuStaticAvailability("amd64")
if err != nil {
t.Errorf("expected no error, got: %s", err)
}
if absolutePath != getCwd()+"/resources/testdata/mockbin/qemu-x86_64-static" {
t.Error("expected absolute path to qemu-static binary to be the same as the mock binary")
}
if binary != "qemu-x86_64-static" {
t.Error("expected binary name to be the same as the mock binary")
}
}
func TestExtractPayload(t *testing.T) {
path := getCwd() + "/resources/testdata/valid_config.json"
config, err := parseConfiguration(path)
if err != nil {
t.Errorf("expected no parsing error, got: %s", err)
}
builder := NewBuilder(config, "amd64", getCwd(), os.Stdout, os.Stderr)
builder.rootfs = os.TempDir()
builder.extractPayload()
defer os.Remove(builder.rootfs + "/afile.txt")
if _, err := os.Stat(builder.rootfs + "/afile.txt"); os.IsNotExist(err) {
t.Errorf("expected file 'afile' to exist in rootfs after extracting payload")
}
}
// TODO: We also need to test mount operations and the building of a rootfs.
// This may require mocking of mount and unmount operations and using fake chroot.