forked from carimura/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
50 lines (46 loc) · 880 Bytes
/
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 (
"bytes"
"fmt"
"os"
"os/exec"
"path"
"strings"
"testing"
)
func TestMainCommands(t *testing.T) {
testCommands := []string{
"init",
"apps",
"routes",
"images",
"lambda",
"version",
"build",
"bump",
"deploy",
"run",
"push",
"logs",
"calls",
"call",
}
tmp := os.TempDir()
fnTestBin := path.Join(tmp, "fn-test")
res, err := exec.Command("go", "build", "-o", fnTestBin).CombinedOutput()
fmt.Println(string(res))
if err != nil {
t.Fatalf("Failed to build fn: err: %s", err)
}
// Change to the tmp dir that contains the cli to run tests
if err := os.Chdir(tmp); err != nil {
t.Fatal(err)
}
for _, cmd := range testCommands {
res, err := exec.Command(fnTestBin, strings.Split(cmd, " ")...).CombinedOutput()
if bytes.Contains(res, []byte("command not found")) {
t.Error(err)
}
}
os.Remove(fnTestBin)
}