graphql-engine/cli/commands/init_test.go
Kali Vara Purushotham Santhati f47095ff55 cli: init --endpoint intializes the project with metadata and migrations from HGE
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2409
Co-authored-by: Ajay Tripathi <24985760+atb00ker@users.noreply.github.com>
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: 06bb3462ffe1604b80a4afde241568790aaa6704
2021-10-07 14:24:52 +00:00

121 lines
3.7 KiB
Go

package commands
import (
"fmt"
"os"
"path/filepath"
"github.com/Pallinder/go-randomdata"
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("hasura init --endpoint (config v3)", func() {
var projectDirectory string
var teardown func()
var hgeEndpoint string
sourceName := randomdata.SillyName()
BeforeEach(func() {
projectDirectory = testutil.RandDirName()
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpoint = fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
connectionString, teardownPG := testutil.StartPGContainer(GinkgoT())
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionString, sourceName)
copyTestConfigV3Project(projectDirectory)
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
editSourceNameInConfigV3ProjectTemplate(projectDirectory, "default", connectionString)
teardown = func() {
os.RemoveAll(projectDirectory)
teardownHGE()
teardownPG()
}
})
AfterEach(func() {
teardown()
})
It("should create directory with metadata and migrations from server", func() {
Context("create migrations and apply those on server", func() {
testMigrateApply(projectDirectory, []string{"--database-name", sourceName})
})
Context("test init --endpoint for config v2", func() {
err := os.RemoveAll(projectDirectory)
Expect(err).To(BeNil())
session := testutil.Hasura(testutil.CmdOpts{
Args: []string{"init", projectDirectory, "--endpoint", hgeEndpoint, "--fetch"},
})
wantKeywordList := []string{
fmt.Sprintf("cd %s", projectDirectory),
"hasura console",
"Metadata exported",
"migrations applied",
}
Eventually(session, timeout).Should(Exit(0))
for _, keyword := range wantKeywordList {
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
}
fileInfos, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", sourceName))
Expect(err).To(BeNil())
Expect(len(fileInfos)).Should(BeEquivalentTo(1))
})
})
})
var _ = Describe("hasura init --endpoint (config v2)", func() {
var projectDirectory string
var teardown func()
var hgeEndpoint string
BeforeEach(func() {
projectDirectory = testutil.RandDirName()
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpoint = fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
copyTestConfigV2Project(projectDirectory)
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
teardown = func() {
os.RemoveAll(projectDirectory)
teardownHGE()
}
})
AfterEach(func() {
teardown()
})
It("should create directory with metadata and migrations from server", func() {
Context("create migrations and apply those on server", func() {
testMigrateApply(projectDirectory, nil)
})
Context("test init --endpoint for config v2", func() {
err := os.RemoveAll(projectDirectory)
Expect(err).To(BeNil())
session := testutil.Hasura(testutil.CmdOpts{
Args: []string{"init", projectDirectory, "--endpoint", hgeEndpoint, "--version", "2", "--fetch"},
})
wantKeywordList := []string{
fmt.Sprintf("cd %s", projectDirectory),
"hasura console",
"Metadata exported",
"migrations applied",
}
Eventually(session, timeout).Should(Exit(0))
for _, keyword := range wantKeywordList {
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
}
fileInfos, err := os.ReadDir(filepath.Join(projectDirectory, "migrations"))
Expect(err).To(BeNil())
Expect(len(fileInfos)).Should(BeEquivalentTo(1))
})
})
})