forked from roots/trellis-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
50 lines (39 loc) · 1.14 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
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/mitchellh/cli"
"github.com/roots/trellis-cli/command"
)
func TestIntegrationForceNoPlugin(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
bin := os.Getenv("TEST_BINARY")
if bin == "" {
t.Error("TEST_BINARY not supplied")
}
if _, err := os.Stat(bin); os.IsNotExist(err) {
t.Error(bin + " not exist")
}
tempDir := t.TempDir()
file, err := os.Create(filepath.Join(tempDir, "trellis-abc"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if err = os.Chmod(file.Name(), 0111); err != nil {
t.Fatalf("unexpected error: %v", err)
}
mockUi := cli.NewMockUi()
trellisCommand := command.WithOptions(command.WithUiOutput(mockUi)).Cmd(bin, []string{"--help"})
trellisCommand.Env = []string{"PATH=" + tempDir + ":$PATH", "TRELLIS_LOAD_PLUGINS=false"}
trellisCommand.Run()
output := mockUi.ErrorWriter.String()
for _, unexpected := range []string{"Available third party plugin commands are", "abc"} {
if strings.Contains(output, unexpected) {
t.Errorf("unexpected output %q to contain %q", output, unexpected)
}
}
}