mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
1998e211af
* remove docker from migrate cmd test * export migration status * [cli] add fake writer for spinner * Update console.go * Update migrate_test.go
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"math/rand"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/briandowns/spinner"
|
|
"github.com/hasura/graphql-engine/cli"
|
|
"github.com/hasura/graphql-engine/cli/commands"
|
|
"github.com/hasura/graphql-engine/cli/util/fake"
|
|
"github.com/sirupsen/logrus/hooks/test"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func init() {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
}
|
|
|
|
func TestPrepare(t *testing.T) {
|
|
logger, _ := test.NewNullLogger()
|
|
ec := &cli.ExecutionContext{
|
|
Logger: logger,
|
|
Spinner: spinner.New(spinner.CharSets[7], 100*time.Millisecond),
|
|
}
|
|
ec.Spinner.Writer = &fake.FakeWriter{}
|
|
err := ec.Prepare()
|
|
if err != nil {
|
|
t.Fatalf("prepare failed: %v", err)
|
|
}
|
|
if ec.CMDName == "" {
|
|
t.Fatalf("expected CMDName, got: %v", ec.CMDName)
|
|
}
|
|
if ec.Spinner == nil {
|
|
t.Fatal("got spinner empty")
|
|
}
|
|
if ec.Logger == nil {
|
|
t.Fatal("got empty logger")
|
|
}
|
|
if ec.GlobalConfigDir == "" {
|
|
t.Fatalf("global config dir: expected $HOME/%s, got %s", cli.GLOBAL_CONFIG_DIR_NAME, ec.GlobalConfigDir)
|
|
}
|
|
if ec.GlobalConfigFile == "" {
|
|
t.Fatalf("global config file: expected $HOME/%s/%s, got %s", cli.GLOBAL_CONFIG_DIR_NAME, cli.GLOBAL_CONFIG_FILE_NAME, ec.GlobalConfigFile)
|
|
}
|
|
if ec.Config == nil {
|
|
t.Fatal("nil HasuraGraphQLConfig")
|
|
}
|
|
}
|
|
|
|
func TestValidate(t *testing.T) {
|
|
logger, _ := test.NewNullLogger()
|
|
ec := &cli.ExecutionContext{
|
|
Logger: logger,
|
|
Spinner: spinner.New(spinner.CharSets[7], 100*time.Millisecond),
|
|
}
|
|
ec.Spinner.Writer = &fake.FakeWriter{}
|
|
ec.ExecutionDirectory = filepath.Join(os.TempDir(), "hasura-gql-tests-"+strconv.Itoa(rand.Intn(1000)))
|
|
ec.Viper = viper.New()
|
|
|
|
// validate a directory created by init
|
|
initCmd := commands.NewInitCmd(ec)
|
|
initCmd.Flags().Set("directory", ec.ExecutionDirectory)
|
|
err := initCmd.Execute()
|
|
if err != nil {
|
|
t.Fatalf("execution failed: %v", err)
|
|
}
|
|
err = ec.Validate()
|
|
if err != nil {
|
|
t.Fatalf("validate failed: %v", err)
|
|
}
|
|
|
|
// remove config.yaml and validate, should result in an error
|
|
err = os.Remove(filepath.Join(ec.ExecutionDirectory, "config.yaml"))
|
|
if err != nil {
|
|
t.Fatalf("remove failed: %v", err)
|
|
}
|
|
err = ec.Validate()
|
|
if err == nil {
|
|
t.Fatal("validate succeeded with no config.yaml")
|
|
}
|
|
|
|
os.RemoveAll(ec.ExecutionDirectory)
|
|
}
|