-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlope_integration_test.go
133 lines (125 loc) · 2.16 KB
/
lope_integration_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
var binaryName = filepath.FromSlash("./lope")
func init() {
cmd := exec.Command("go", "build")
err := cmd.Run()
if err != nil {
panic(err)
}
cmd = exec.Command("go", "build", "-o", "lope", "cmdProxy.go")
cmd.Env = os.Environ()
cmd.Env = append(
cmd.Env,
"GOOS=linux",
"GOARCH=amd64",
"CGO_ENABLED=0",
)
cmd.Dir = "cmdProxy"
err = cmd.Run()
if err != nil {
panic(err)
}
if err := os.Chmod(filepath.FromSlash("cmdProxy/lope"), 0755); err != nil {
panic(err)
}
}
func TestLopeCli(t *testing.T) {
var tests = []struct {
description string
cmd []string
match []string
}{
{
"Run lope with no arguments and get the help message",
[]string{},
[]string{
"Usage of lope",
},
},
{
"Run a basic alpine image",
[]string{
"-noTty",
"alpine",
"ls",
},
[]string{
"README.md",
},
},
{
"Run docker inside lope",
[]string{
"-noTty",
"-addDocker",
"alpine",
"docker",
"ps",
},
[]string{
"CONTAINER",
"STATUS",
"lope",
},
},
{
"Run a command via the command proxy api",
[]string{
"-noTty",
"-cmdProxy",
"alpine",
"wget", "-q", "-O-",
`--post-data='{"command":"lope", "args": ["-noTty", "alpine", "ls"]}'`,
"--header=Content-Type:application/json",
"$LOPE_PROXY_ADDR",
},
[]string{
"README.md",
},
},
{
"Run a command via the command proxy cli",
[]string{
"-noTty",
"-cmdProxy",
"alpine",
"cmdProxy/lope", "-noTty", "alpine", "ls",
},
[]string{
"README.md",
},
},
{
"Run a command with an extra docker arg",
[]string{
"-noTty",
"-arg",
"--hostname=crazybus",
"alpine",
"hostname",
},
[]string{
"crazybus",
},
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
cmd := exec.Command(binaryName, test.cmd...)
out, _ := cmd.CombinedOutput()
output := string(out)
for _, match := range test.match {
if !strings.Contains(output, match) {
t.Errorf("expected %q to contain %q", output, match)
}
}
})
}
}