graphql-engine/cli/commands/init_test.go
Aravind Shankar 260d565e6e cli: tests for metadata commands (#18)
* [cli] added urlPrefix, consoleMode

* [cli] fix: down=all should throw error if down migration is missing

* [cli] added tests for metadata
2018-06-29 15:32:33 +05:30

60 lines
1.2 KiB
Go

package commands
import (
"math/rand"
"os"
"path/filepath"
"strconv"
"testing"
"time"
"github.com/hasura/graphql-engine/cli"
"github.com/sirupsen/logrus/hooks/test"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func TestInitCmd(t *testing.T) {
logger, _ := test.NewNullLogger()
tt := []struct {
name string
opts *initOptions
err error
}{
{"only-init-dir", &initOptions{
EC: &cli.ExecutionContext{
Logger: logger,
},
Endpoint: "",
AccessKey: "",
InitDir: filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000))),
}, nil},
{"with-endpoint-flag", &initOptions{
EC: &cli.ExecutionContext{
Logger: logger,
},
Endpoint: "https://localhost:8080",
AccessKey: "",
InitDir: filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000))),
}, nil},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
err := tc.opts.EC.Prepare()
if err != nil {
t.Fatalf("%s: prep failed: %v", tc.name, err)
}
err = tc.opts.run()
if err != tc.err {
t.Fatalf("%s: expected %v, got %v", tc.name, tc.err, err)
} else {
// TODO: (shahidhk) need to verify the contents of the spec generated
os.RemoveAll(tc.opts.InitDir)
}
})
}
}