-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvaranny_test.go
79 lines (65 loc) · 1.74 KB
/
varanny_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"os"
"os/exec"
"path"
"testing"
)
func TestAssertExecutableError(t *testing.T) {
path := "this-command-does-not-exist"
err := assertExecutable(path)
if err == nil {
t.Errorf("Expected %s to be not executable, but got %s", path, err)
}
}
func TestAssertExecutable(t *testing.T) {
path := "echo" // Use a standard command that exists on most systems
err := assertExecutable(path)
if err != nil {
t.Errorf("Expected %s to be executable, but got %s", path, err)
}
}
func TestGetConfigPath(t *testing.T) {
configPath, err := getConfigPath()
if err != nil {
t.Fatalf("Cannot find config %s", err)
}
if configPath == "" {
t.Error("Expected config path to be not empty")
}
}
func TestGetConfig(t *testing.T) {
config, err := getConfig(path.Join("sample-configs", "varanny.test.json"))
if err != nil {
t.Fatalf("Cannot find config %s", err)
}
if config == nil {
t.Error("Expected config to be not nil")
}
}
func TestCreateCommand(t *testing.T) {
path := "echo" // Use a standard command that exists on most systems
args := []string{"arg1", "arg2"}
cmd := createCommand(nil, path, args...)
expectedPath, err := exec.LookPath(path)
if err != nil {
t.Fatalf("Cannot find command %s in PATH: %v", path, err)
}
if cmd.Path != expectedPath {
t.Errorf("Expected command path to be %s, but got %s", expectedPath, cmd.Path)
}
if len(cmd.Args) != len(args)+1 {
t.Errorf("Expected command arguments length to be %d, but got %d", len(args)+1, len(cmd.Args))
}
for i, arg := range args {
if cmd.Args[i+1] != arg {
t.Errorf("Expected argument at index %d to be %s, but got %s", i+1, arg, cmd.Args[i+1])
}
}
}
func TestMain(m *testing.M) {
// Do setup here
code := m.Run()
// Do teardown here
os.Exit(code)
}