Skip to content

Commit 3e3f43c

Browse files
authored
Merge pull request #17 from owenthereal/add_ftest
Backfill ftest for commands
2 parents 84e7607 + 2ca69fa commit 3e3f43c

File tree

1 file changed

+93
-26
lines changed

1 file changed

+93
-26
lines changed

ftest/ftest_test.go

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,42 +51,109 @@ func TestMain(m *testing.M) {
5151
os.Exit(m.Run())
5252
}
5353

54-
func TestInstaller(t *testing.T) {
55-
cmd := exec.Command("sh", flagInstallPath, "--skip-prompt")
56-
cmd.Env = append(os.Environ(), "GOUP_UPDATE_ROOT=file://"+goupBinDir)
54+
func TestGoup(t *testing.T) {
55+
t.Run("installer", func(t *testing.T) {
56+
cmd := exec.Command("sh", flagInstallPath, "--skip-prompt")
57+
cmd.Env = append(os.Environ(), "GOUP_UPDATE_ROOT=file://"+goupBinDir)
58+
execCmd(t, cmd)
59+
60+
// check file exists
61+
filesShouldExist := []string{
62+
commands.GoupDir(),
63+
commands.GoupEnvFile(),
64+
commands.GoupBinDir(),
65+
commands.GoupCurrentDir(),
66+
commands.GoupCurrentBinDir(),
67+
}
68+
for _, f := range filesShouldExist {
69+
if _, err := os.Stat(f); os.IsNotExist(err) {
70+
t.Error(err)
71+
}
72+
}
5773

58-
out, err := cmd.CombinedOutput()
59-
if err != nil {
60-
t.Fatalf("%s: %s", out, err)
61-
}
74+
// check profiles
75+
for _, f := range commands.ProfileFiles {
76+
ok, err := fileContains(f, commands.ProfileFileSourceContent)
77+
if err != nil {
78+
t.Error(err)
79+
}
80+
81+
if !ok {
82+
t.Errorf("%s does not source goup", f)
83+
}
84+
}
85+
})
6286

63-
fmt.Println(string(out))
87+
goupBin := filepath.Join(commands.GoupBinDir(), "goup")
6488

65-
// check file exists
66-
filesShouldExist := []string{
67-
commands.GoupDir(),
68-
commands.GoupEnvFile(),
69-
commands.GoupBinDir(),
70-
commands.GoupCurrentDir(),
71-
commands.GoupCurrentBinDir(),
72-
}
73-
for _, f := range filesShouldExist {
74-
if _, err := os.Stat(f); os.IsNotExist(err) {
75-
t.Error(err)
89+
t.Run("goup install", func(t *testing.T) {
90+
cmd := exec.Command(goupBin, "install", "1.15.2")
91+
execCmd(t, cmd)
92+
})
93+
94+
t.Run("goup show", func(t *testing.T) {
95+
cmd := exec.Command(goupBin, "show")
96+
out := execCmd(t, cmd)
97+
98+
if want, got := []byte("1.15.2"), out; !bytes.Contains(got, want) {
99+
t.Fatalf("goup show failed: want=%s got=%s", want, out)
76100
}
77-
}
101+
})
102+
103+
t.Run("goup ls-ver", func(t *testing.T) {
104+
cmd := exec.Command(goupBin, "ls-ver")
105+
out := execCmd(t, cmd)
106+
107+
if want, got := []byte("1.15.2"), out; !bytes.Contains(got, want) {
108+
t.Fatalf("goup ls-ver failed: want=%s got=%s", want, out)
109+
}
110+
})
111+
112+
t.Run("goup remove", func(t *testing.T) {
113+
cmd := exec.Command(goupBin, "remove", "1.15.2")
114+
execCmd(t, cmd)
115+
})
78116

79-
// check profiles
80-
for _, f := range commands.ProfileFiles {
81-
ok, err := fileContains(f, commands.ProfileFileSourceContent)
117+
t.Run("goup show again", func(t *testing.T) {
118+
cmd := exec.Command(goupBin, "show")
119+
out := execCmd(t, cmd)
120+
121+
if want, got := []byte("1.15.2"), out; bytes.Contains(got, want) {
122+
t.Fatalf("goup show again failed: want=%s got=%s", want, out)
123+
}
124+
})
125+
126+
t.Run("goup upgrade", func(t *testing.T) {
127+
cmd := exec.Command(goupBin, "upgrade", "0.1.4")
128+
cmd.Env = append(os.Environ(), fmt.Sprintf("PATH=%s:$PATH", filepath.Dir(goupBin)))
129+
out, err := cmd.CombinedOutput()
82130
if err != nil {
83-
t.Error(err)
131+
t.Fatalf("goup upgrade failed: %s: %s", out, err)
84132
}
133+
t.Logf("%s", out)
134+
})
135+
136+
t.Run("goup version", func(t *testing.T) {
137+
cmd := exec.Command(goupBin, "version")
138+
out := execCmd(t, cmd)
85139

86-
if !ok {
87-
t.Errorf("%s does not source goup", f)
140+
if want, got := []byte("0.1.4"), out; !bytes.Contains(got, want) {
141+
t.Fatalf("goup version failed: want=%s got=%s", want, out)
88142
}
143+
})
144+
145+
}
146+
147+
func execCmd(t *testing.T, cmd *exec.Cmd) []byte {
148+
t.Helper()
149+
150+
out, err := cmd.CombinedOutput()
151+
if err != nil {
152+
t.Fatalf("%s: %s", out, err)
89153
}
154+
t.Logf("%s", out)
155+
156+
return out
90157
}
91158

92159
func fileContains(f string, s string) (bool, error) {

0 commit comments

Comments
 (0)