graphql-engine/cli/commands/seed_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

94 lines
3.1 KiB
Go

package commands
import (
"fmt"
"os"
"path/filepath"
"github.com/Pallinder/go-randomdata"
"github.com/hasura/graphql-engine/cli/internal/testutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var testSeedCreate = func(projectDirectory string, globalFlags []string) {
upSql := `CREATE TABLE "public"."table1" ("id" serial NOT NULL, PRIMARY KEY ("id") );
INSERT INTO public.table1 (id) VALUES (1);
INSERT INTO public.table1 (id) VALUES (2);
INSERT INTO public.table1 (id) VALUES (3);
INSERT INTO public.table1 (id) VALUES (4);`
downSql := `DROP TABLE "public"."table1";`
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: append([]string{"migrate", "create", "table1", "--up-sql", upSql, "--down-sql", downSql}, globalFlags...),
WorkingDirectory: projectDirectory,
})
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: append([]string{"migrate", "apply"}, globalFlags...),
WorkingDirectory: projectDirectory,
})
session := testutil.Hasura(testutil.CmdOpts{
Args: append([]string{"seed", "create", "table_seed", "--from-table", "table1"}, globalFlags...),
WorkingDirectory: projectDirectory,
})
Eventually(session, 60*60).Should(Exit(0))
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("created seed file successfully"))
}
var _ = Describe("hasura seed create", func() {
Context("config v3", func() {
var teardown func()
var projectDirectory string
var sourceName string
BeforeEach(func() {
projectDirectory = testutil.RandDirName()
hgeEndPort, teardownHGE := testutil.StartHasuraWithMetadataDatabase(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
connectionUrl, teardownPG := testutil.StartPGContainer(GinkgoT())
sourceName = randomdata.SillyName()
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionUrl, sourceName)
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"init", projectDirectory},
})
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
teardown = func() {
teardownPG()
teardownHGE()
os.RemoveAll(projectDirectory)
}
})
AfterEach(func() { teardown() })
It("can create seeds in config v3", func() {
testSeedCreate(projectDirectory, []string{"--database-name", sourceName})
})
})
Context("config v2", func() {
var teardown func()
var projectDirectoryConfigV2 string
BeforeEach(func() {
projectDirectoryConfigV2 = 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", projectDirectoryConfigV2, "--version", "2"},
})
editEndpointInConfig(filepath.Join(projectDirectoryConfigV2, defaultConfigFilename), hgeEndpoint)
teardown = func() {
teardownHGE()
os.RemoveAll(projectDirectoryConfigV2)
}
})
AfterEach(func() { teardown() })
It("can create seeds in config v2", func() {
testSeedCreate(projectDirectoryConfigV2, nil)
})
})
})