2020-02-24 19:14:46 +03:00
|
|
|
package integrationtest_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/briandowns/spinner"
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
|
|
integrationtest "github.com/hasura/graphql-engine/cli/v2/integration_test"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
2020-02-24 19:14:46 +03:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
v2 "github.com/hasura/graphql-engine/cli/v2/integration_test/v2"
|
|
|
|
v3 "github.com/hasura/graphql-engine/cli/v2/integration_test/v3"
|
2020-02-24 19:14:46 +03:00
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
}
|
2021-02-17 07:20:19 +03:00
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
func TestCommands(t *testing.T) {
|
|
|
|
// Run tests only for config version v2
|
|
|
|
t.Run("config=v2", func(t *testing.T) {
|
|
|
|
ec := cli.NewExecutionContext()
|
|
|
|
ec.Config = &cli.Config{}
|
|
|
|
logger, _ := test.NewNullLogger()
|
|
|
|
ec.Logger = logger
|
|
|
|
ec.Spinner = spinner.New(spinner.CharSets[7], 100*time.Millisecond)
|
|
|
|
ec.Spinner.Writer = ioutil.Discard
|
|
|
|
ec.Viper = viper.New()
|
2021-10-13 17:38:07 +03:00
|
|
|
ec.Stdout = os.Stdout
|
|
|
|
ec.Stderr = os.Stderr
|
2020-02-24 19:14:46 +03:00
|
|
|
|
|
|
|
initDir := filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000)))
|
|
|
|
defer os.RemoveAll(initDir)
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
hasuraPort, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
2021-05-17 03:29:11 +03:00
|
|
|
defer teardown()
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
// This will prepare the execution context, so no need to run ec.Prepare() on all the other tests
|
|
|
|
t.Run("prepare", func(t *testing.T) {
|
|
|
|
integrationtest.TestPrepare(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
// This will init the project dir
|
|
|
|
t.Run("init command", func(t *testing.T) {
|
2021-05-17 03:29:11 +03:00
|
|
|
v2.TestInitCmd(t, ec, initDir, hasuraPort)
|
2020-02-24 19:14:46 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
// This will validate the project dir
|
|
|
|
t.Run("validate", func(t *testing.T) {
|
|
|
|
integrationtest.TestValidate(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("console command", func(t *testing.T) {
|
|
|
|
v2.TestConsoleCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("migrate commands", func(t *testing.T) {
|
|
|
|
v2.TestMigrateCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("metadata commands", func(t *testing.T) {
|
|
|
|
v2.TestMetadataCmd(t, ec)
|
|
|
|
})
|
2020-06-16 15:15:04 +03:00
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("seed create command", func(t *testing.T) {
|
|
|
|
v2.TestSeedsCreateCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("seed apply commands", func(t *testing.T) {
|
|
|
|
v2.TestSeedsApplyCmd(t, ec)
|
|
|
|
})
|
2020-02-24 19:14:46 +03:00
|
|
|
})
|
2021-01-18 20:11:05 +03:00
|
|
|
t.Run("config=v3", func(t *testing.T) {
|
2020-06-24 13:38:48 +03:00
|
|
|
ec := cli.NewExecutionContext()
|
|
|
|
ec.Config = &cli.Config{}
|
|
|
|
logger, _ := test.NewNullLogger()
|
|
|
|
ec.Logger = logger
|
|
|
|
ec.Spinner = spinner.New(spinner.CharSets[7], 100*time.Millisecond)
|
|
|
|
ec.Spinner.Writer = ioutil.Discard
|
|
|
|
ec.Viper = viper.New()
|
2021-10-13 17:38:07 +03:00
|
|
|
ec.Stdout = os.Stdout
|
|
|
|
ec.Stderr = os.Stderr
|
2020-06-24 13:38:48 +03:00
|
|
|
|
|
|
|
initDir := filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000)))
|
|
|
|
defer os.RemoveAll(initDir)
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
hasuraPort, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
2021-05-17 03:29:11 +03:00
|
|
|
defer teardown()
|
|
|
|
|
2020-06-24 13:38:48 +03:00
|
|
|
// This will prepare the execution context, so no need to run ec.Prepare() on all the other tests
|
|
|
|
t.Run("prepare", func(t *testing.T) {
|
|
|
|
integrationtest.TestPrepare(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
// This will init the project dir
|
|
|
|
t.Run("init command", func(t *testing.T) {
|
2021-05-17 03:29:11 +03:00
|
|
|
v3.TestInitCmd(t, ec, initDir, hasuraPort)
|
2020-06-24 13:38:48 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
// This will validate the project dir
|
|
|
|
t.Run("validate", func(t *testing.T) {
|
|
|
|
integrationtest.TestValidate(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
2021-01-18 20:11:05 +03:00
|
|
|
t.Run("console command", func(t *testing.T) {
|
|
|
|
v3.TestConsoleCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("migrate commands", func(t *testing.T) {
|
|
|
|
v3.TestMigrateCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("metadata commands", func(t *testing.T) {
|
|
|
|
v3.TestMetadataCmd(t, ec)
|
|
|
|
})
|
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("seed create command", func(t *testing.T) {
|
|
|
|
v3.TestSeedsCreateCmd(t, ec)
|
2020-06-24 13:38:48 +03:00
|
|
|
})
|
|
|
|
|
2021-01-18 20:11:05 +03:00
|
|
|
skip(t)
|
|
|
|
t.Run("seed apply commands", func(t *testing.T) {
|
|
|
|
v3.TestSeedsApplyCmd(t, ec)
|
|
|
|
})
|
2021-09-29 09:14:15 +03:00
|
|
|
|
|
|
|
skip(t)
|
|
|
|
t.Run("deploy commands", func(t *testing.T) {
|
|
|
|
v3.TestDeployCmd(t, ec)
|
|
|
|
})
|
2020-06-24 13:38:48 +03:00
|
|
|
})
|
2020-02-24 19:14:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func skip(t *testing.T) {
|
|
|
|
if t.Failed() {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
}
|