graphql-engine/cli/commands/migrate_create_test.go
Aravind K P d8198a8bad cli,ci: testsuite enhancements
- remove `HASURA_TEST_CLI_HGE_DOCKER_TAG` & `HASURA_TEST_CLI_HGE_DOCKER_REPO` env variables
- add `HASURA_TEST_CLI_HGE_DOCKER_IMAGE` environment variable to configure hge image used in tests
- add template test project directories
- add helper functions to manipulate the template projects in individual tests
- add config v2 tests

Co-authored-by: Kali Vara Purushotham Santhati <72007599+purush7@users.noreply.github.com>
GitOrigin-RevId: 009a74c042861ff0a8dec2b06002e55de3a8a629
2021-06-03 13:27:24 +00:00

133 lines
3.9 KiB
Go

package commands
import (
"fmt"
"os"
"path/filepath"
"github.com/hasura/graphql-engine/cli/internal/testutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("hasura migrate create (config v3)", func() {
var projectDirectory string
var teardown func()
BeforeEach(func() {
projectDirectory = testutil.RandDirName()
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"init", projectDirectory},
})
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
teardown = func() {
os.RemoveAll(projectDirectory)
teardownHGE()
}
})
AfterEach(func() { teardown() })
It("can create migrations for default database", func() {
migrationName := "create_schema_testing"
session := testutil.Hasura(testutil.CmdOpts{
Args: []string{
"migrate",
"create",
migrationName,
"--up-sql",
"create schema \"testing\";",
"--down-sql",
"drop schema \"testing\" cascade;",
"--database-name", "default",
},
WorkingDirectory: projectDirectory,
})
wantKeywordList := []string{
"Migrations files created",
migrationName,
"version",
}
Eventually(session, 60*60).Should(Exit(0))
for _, keyword := range wantKeywordList {
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
}
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", "default"))
Expect(err).To(BeNil())
for _, d := range dirs {
Expect(d.Name()).Should(ContainSubstring(migrationName))
}
})
})
var _ = Describe("hasura migrate create (config v2)", func() {
var projectDirectoryLatest, projectDirectoryV13 string
var session *Session
var teardown func()
BeforeEach(func() {
projectDirectoryLatest = testutil.RandDirName()
hgeEndPortLatest, teardownHGELatest := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpointLatest := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPortLatest)
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"init", projectDirectoryLatest, "--version", "2"},
})
editEndpointInConfig(filepath.Join(projectDirectoryLatest, defaultConfigFilename), hgeEndpointLatest)
projectDirectoryV13 = testutil.RandDirName()
hgeEndPortV13, teardownHGEV13 := testutil.StartHasura(GinkgoT(), "hasura/graphql-engine:v1.3.3")
hgeEndpointV13 := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPortV13)
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"init", projectDirectoryV13, "--version", "2"},
})
editEndpointInConfig(filepath.Join(projectDirectoryV13, defaultConfigFilename), hgeEndpointV13)
teardown = func() {
session.Kill()
os.RemoveAll(projectDirectoryLatest)
os.RemoveAll(projectDirectoryV13)
teardownHGEV13()
teardownHGELatest()
}
})
AfterEach(func() { teardown() })
It("can create migration files", func() {
test := func(projectDirectory string) {
migrationName := "create_schema_testing"
wantKeywordList := []string{
"Migrations files created",
migrationName,
"version",
}
session = testutil.Hasura(testutil.CmdOpts{
Args: []string{
"migrate",
"create",
migrationName,
"--up-sql", "create schema \"testing\";",
"--down-sql",
"drop schema \"testing\" cascade;",
},
WorkingDirectory: projectDirectory,
})
Eventually(session, 60*60).Should(Exit(0))
for _, keyword := range wantKeywordList {
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
}
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations"))
Expect(err).To(BeNil())
for _, d := range dirs {
Expect(d.Name()).Should(ContainSubstring(migrationName))
}
}
test(projectDirectoryLatest)
test(projectDirectoryV13)
})
})