fn test main commands (#481)

This commit is contained in:
Pedro Nasser
2017-01-10 20:42:18 -02:00
committed by C Cirello
parent 6e28b3e740
commit afb684b6a8
2 changed files with 45 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ func aliasesFn() []cli.Command {
return cmds
}
func main() {
func newFn() *cli.App {
app := cli.NewApp()
app.Name = "fn"
app.Version = fnversion
@@ -77,6 +77,11 @@ GLOBAL OPTIONS:
version(),
}
app.Commands = append(app.Commands, aliasesFn()...)
return app
}
func main() {
app := newFn()
app.Run(os.Args)
}

39
fn/main_test.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"bytes"
"os"
"os/exec"
"path"
"strings"
"testing"
)
func TestMainCommands(t *testing.T) {
testCommands := []string{
"init",
"apps",
"routes",
"images",
"lambda",
"version",
"build",
"bump",
"deploy",
"run",
"push",
}
fnTestBin := path.Join(os.TempDir(), "fn-test")
exec.Command("go", "build", "-o", fnTestBin).Run()
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)
}