-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcli_test.go
70 lines (65 loc) · 1.31 KB
/
cli_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
package ghg
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
)
var tempdir string
func TestMain(m *testing.M) {
tempd, err := ioutil.TempDir("", "ghgtest-")
if err != nil {
panic("fialed to create tempdir in test")
}
os.Setenv(EnvHome, tempd)
tempdir = tempd
exit := m.Run()
os.RemoveAll(tempdir)
os.Exit(exit)
}
var tests = []struct {
name string
input string
out string
exitCode int
}{
{
name: "simple",
input: "Songmu/ghg@v0.0.1",
out: "ghg",
exitCode: 0,
},
{
name: "naked binary",
input: "bcicen/ctop@v0.4.1",
out: "ctop",
exitCode: 0,
},
}
func TestGet(t *testing.T) {
for _, tt := range tests {
exitCode := (&CLI{
ErrStream: ioutil.Discard,
OutStream: ioutil.Discard,
}).Run([]string{
"get",
tt.input,
})
if exitCode != tt.exitCode {
t.Errorf("%s(exitCode): out=%d want=%d", tt.name, exitCode, tt.exitCode)
}
expectFile := tt.out
if runtime.GOOS == "windows" {
expectFile += ".exe"
}
fname := filepath.Join(tempdir, "bin", expectFile)
fi, err := os.Stat(fname)
if err != nil {
t.Errorf("%s(exists): %q shoud be exists, but not found: %s", tt.name, expectFile, err)
}
if (fi.Mode() & 0111) == 0 {
t.Errorf("%s(executable): %q shoud be executable, but not.", tt.name, expectFile)
}
}
}