Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sundowndev
GitHub Repository: sundowndev/phoneinfoga
Path: blob/master/lib/remote/scanner_test.go
988 views
1
package remote
2
3
import (
4
"fmt"
5
"os"
6
"path/filepath"
7
"testing"
8
9
"github.com/stretchr/testify/assert"
10
)
11
12
func Test_ValidatePlugin_Errors(t *testing.T) {
13
invalidPluginAbsPath, err := filepath.Abs("testdata/invalid.so")
14
if err != nil {
15
assert.FailNow(t, "failed to get the absolute path of test file: %v", err)
16
}
17
18
testcases := []struct {
19
name string
20
path string
21
wantErr string
22
}{
23
{
24
name: "test with invalid path",
25
path: "testdata/doesnotexist",
26
wantErr: "given path testdata/doesnotexist does not exist",
27
},
28
{
29
name: "test with invalid plugin",
30
path: "testdata/invalid.so",
31
wantErr: fmt.Sprintf("given plugin testdata/invalid.so is not valid: plugin.Open(\"testdata/invalid.so\"): %s: file too short", invalidPluginAbsPath),
32
},
33
}
34
35
for _, tt := range testcases {
36
t.Run(tt.name, func(t *testing.T) {
37
err := OpenPlugin(tt.path)
38
assert.EqualError(t, err, tt.wantErr)
39
})
40
}
41
}
42
43
func TestScannerOptions(t *testing.T) {
44
testcases := []struct {
45
name string
46
opts ScannerOptions
47
check func(*testing.T, ScannerOptions)
48
}{
49
{
50
name: "test GetStringEnv with simple options",
51
opts: map[string]interface{}{
52
"foo": "bar",
53
},
54
check: func(t *testing.T, opts ScannerOptions) {
55
assert.Equal(t, opts.GetStringEnv("foo"), "bar")
56
assert.Equal(t, opts.GetStringEnv("bar"), "")
57
},
58
},
59
{
60
name: "test GetStringEnv with env vars",
61
opts: map[string]interface{}{
62
"foo_bar": "bar",
63
},
64
check: func(t *testing.T, opts ScannerOptions) {
65
_ = os.Setenv("FOO_BAR", "secret")
66
defer os.Unsetenv("FOO_BAR")
67
68
assert.Equal(t, opts.GetStringEnv("FOO_BAR"), "secret")
69
assert.Equal(t, opts.GetStringEnv("foo_bar"), "bar")
70
assert.Equal(t, opts.GetStringEnv("foo"), "")
71
},
72
},
73
}
74
75
for _, tt := range testcases {
76
t.Run(tt.name, func(t *testing.T) {
77
tt.check(t, tt.opts)
78
})
79
}
80
}
81
82