29 lines
779 B
Go
29 lines
779 B
Go
package testing_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"metis/pkg/inject"
|
|
)
|
|
|
|
func TestInjectWrite(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
boot := filepath.Join(tmp, "boot")
|
|
root := filepath.Join(tmp, "root")
|
|
inj := inject.Injector{BootPath: boot, RootPath: root}
|
|
files := []inject.FileSpec{
|
|
{Path: "config.txt", Content: []byte("bootcfg"), Mode: 0o644, RootFS: false},
|
|
{Path: "etc/hostname", Content: []byte("node"), Mode: 0o644, RootFS: true},
|
|
}
|
|
if err := inj.Write(files); err != nil {
|
|
t.Fatalf("Write: %v", err)
|
|
}
|
|
if got := readFile(t, filepath.Join(boot, "config.txt")); string(got) != "bootcfg" {
|
|
t.Fatalf("boot file = %q", got)
|
|
}
|
|
if got := readFile(t, filepath.Join(root, "etc/hostname")); string(got) != "node" {
|
|
t.Fatalf("root file = %q", got)
|
|
}
|
|
}
|