-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
81 lines (65 loc) · 1.44 KB
/
main_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
package main
import (
"bytes"
"io"
"os"
"strings"
"testing"
)
func TestDefaultVersion(t *testing.T) {
os.Args = []string{"./seal-cli", "version"}
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
main()
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
w.Close()
os.Stdout = old
out := <-outC
if !strings.HasPrefix(out, "dev") {
t.Errorf("expected version to be dev, but got %s", out)
}
}
func TestCluserWideScope(t *testing.T) {
os.Args = []string{"./seal-cli", "-h", "http://host", "-s", "MySecret", "-dry-run"}
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
main()
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
w.Close()
os.Stdout = old
out := <-outC
if !strings.Contains(out, "cluster-wide") {
t.Errorf("expected kubeseal CMD to be called with cluster-wide scope, but got %s", out)
}
}
func TestNamespaceWideScope(t *testing.T) {
os.Args = []string{"./seal-cli", "-h", "http://host", "-s", "MySecret", "-n", "myspace", "-dry-run"}
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
main()
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
w.Close()
os.Stdout = old
out := <-outC
if !strings.Contains(out, "namespace-wide") {
t.Errorf("expected kubeseal CMD to be called with namespace-wide scope, but got %s", out)
}
}