-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcmd_test.go
112 lines (95 loc) · 2.28 KB
/
cmd_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package executor
import (
"os"
"testing"
"time"
"golang.org/x/sync/errgroup"
"github.com/picostack/pico/secret/memory"
"github.com/picostack/pico/task"
"github.com/stretchr/testify/assert"
_ "github.com/picostack/pico/logger"
)
func TestMain(m *testing.M) {
os.Mkdir(".test", os.ModePerm) //nolint:errcheck
os.Exit(m.Run())
}
func TestCommandExecutor(t *testing.T) {
ce := NewCommandExecutor(&memory.MemorySecrets{
Secrets: map[string]map[string]string{
"test": map[string]string{
"SOME_SECRET": "123",
},
},
}, false, "pico", "GLOBAL_")
bus := make(chan task.ExecutionTask)
g := errgroup.Group{}
g.Go(func() error {
bus <- task.ExecutionTask{
Target: task.Target{
Name: "test_executor",
Up: []string{"git", "init"},
},
Path: "./.test",
}
return nil
})
go ce.Subscribe(bus)
if err := g.Wait(); err != nil {
t.Error(err)
}
// wait for the task to be consumed and executed
time.Sleep(time.Second)
if _, err := os.Stat(".test/.git"); err != nil {
t.Error("expected path .test/.git to exist:", err)
}
os.RemoveAll(".test/.git")
}
func TestCommandPrepareWithoutPassthrough(t *testing.T) {
ce := NewCommandExecutor(&memory.MemorySecrets{
Secrets: map[string]map[string]string{
"test": map[string]string{
"SOME_SECRET": "123",
},
},
}, false, "pico", "GLOBAL_")
ex, err := ce.prepare("test", "./", false, map[string]string{
"DATA_DIR": "/data/shared",
})
assert.NoError(t, err)
assert.Equal(t, exec{
path: "./",
env: map[string]string{
"SOME_SECRET": "123",
"DATA_DIR": "/data/shared",
},
shutdown: false,
passEnvironment: false,
}, ex)
}
func TestCommandPrepareWithGlobal(t *testing.T) {
ce := NewCommandExecutor(&memory.MemorySecrets{
Secrets: map[string]map[string]string{
"test": map[string]string{
"SOME_SECRET": "123",
},
"pico": map[string]string{
"GLOBAL_SECRET": "456",
"IGNORE": "this",
},
},
}, false, "pico", "GLOBAL_")
ex, err := ce.prepare("test", "./", false, map[string]string{
"DATA_DIR": "/data/shared",
})
assert.NoError(t, err)
assert.Equal(t, exec{
path: "./",
env: map[string]string{
"SOME_SECRET": "123",
"SECRET": "456",
"DATA_DIR": "/data/shared",
},
shutdown: false,
passEnvironment: false,
}, ex)
}