generated from Vanilla-OS/vib-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin_test.go
64 lines (57 loc) · 3.36 KB
/
plugin_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
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2024, axtlos <[email protected]>
// SPDX-License-Identifier: GPL-3.0-ONLY
package main
import (
"encoding/json"
"fmt"
"os"
"testing"
)
type testCases struct {
module interface{}
expected string
}
var test = []testCases{
// No custom, location /fsguard, generate key, keypath /fsguard/keys, filelists /bin
{
FsGuardModule{Name: "testCase1", CustomFsGuard: false, FsGuardLocation: "/fsguard", GenerateKey: true, KeyPath: "/fsguard/keys", FilelistPaths: []string{"/bin"}},
"mkdir /FsGuard && chmod +x /sources/testCase1/genfilelist.py && minisign -WG -s ./minisign.key && python3 /sources/testCase1/genfilelist.py /bin /FsGuard/filelist /fsguard && minisign -Sm /FsGuard/filelist -p .//minisign.pub -s .//minisign.key && touch /FsGuard/signature && echo -n \"----begin attach----\" >> /FsGuard/signature && cat /FsGuard/filelist.minisig >> /FsGuard/signature && echo -n \"----begin second attach----\" >> /FsGuard/signature && tail -n1 .//minisign.pub >> /FsGuard/signature && cat /FsGuard/signature >> /sources/testCase1/FsGuard && mv /sources/testCase1/FsGuard /fsguard && rm ./minisign.key ./minisign.pub",
},
// With custom, location /fsguard, dont generate key, keypath /fsguard/keys, filelists /bin
{
FsGuardModule{Name: "testCase2", CustomFsGuard: true, FsGuardLocation: "/fsguard", GenerateKey: false, KeyPath: "/fsguard/keys", FilelistPaths: []string{"/bin"}},
"mkdir /FsGuard && chmod +x /sources/testCase2/genfilelist.py && python3 /sources/testCase2/genfilelist.py /bin /FsGuard/filelist /fsguard && minisign -Sm /FsGuard/filelist -p /fsguard/keys/minisign.pub -s /fsguard/keys/minisign.key && touch /FsGuard/signature && echo -n \"----begin attach----\" >> /FsGuard/signature && cat /FsGuard/filelist.minisig >> /FsGuard/signature && echo -n \"----begin second attach----\" >> /FsGuard/signature && tail -n1 /fsguard/keys/minisign.pub >> /FsGuard/signature && cat /FsGuard/signature >> /sources/testCase2/FsGuard && mv /sources/testCase2/FsGuard /fsguard",
},
}
var recipe = "{\"Name\":\"fsguard unit test\",\"Id\":\"fsguard\",\"Stages\":[{\"id\":\"test\",\"base\":\"test:latest\",\"singlelayer\":false,\"copy\":null,\"labels\":null,\"env\":null,\"adds\":null,\"args\":null,\"runs\":null,\"expose\":null,\"cmd\":null,\"modules\":[{}],\"Entrypoint\":null}],\"Path\":\"/fakepath/recipe.yml\",\"ParentPath\":\"/fakepath\",\"DownloadsPath\":\"/tmp/fsguard/downloads\",\"SourcesPath\":\"/tmp/fsguard/sources\",\"PluginPath\":\"/plugins\",\"Containerfile\":\"/Containerfile\"}"
func TestBuildModule(t *testing.T) {
err := os.MkdirAll("/tmp/fsguard/downloads", 0o777)
if err != nil {
t.Errorf("%s", err)
}
err = os.MkdirAll("/tmp/fsguard/sources", 0o777)
if err != nil {
t.Errorf("%s", err)
}
for i, testCase := range test {
err = os.RemoveAll("/tmp/fsguard/downloads/*")
if err != nil {
t.Errorf("%s", err)
}
err = os.RemoveAll("/tmp/fsguard/sources/*")
if err != nil {
t.Errorf("%s", err)
}
moduleInterface, err := json.Marshal(testCase.module)
if err != nil {
t.Errorf("Error in json %s", err.Error())
}
output := BuildModule(convertToCString(string(moduleInterface)), convertToCString(recipe))
if convertToGoString(output) != testCase.expected {
t.Errorf("Output %s not equivalent to expected %s", convertToGoString(output), testCase.expected)
} else {
fmt.Printf("-- Testcase %d succeeded --\n", i+1)
}
}
os.RemoveAll("/tmp/fsguard")
}