graphql-engine/cli/commands/metadata_apply_test.go
Kali Vara Purushotham Santhati ca567bf8cb cli: enhance e2e tests
- actions use-codegen
    - Assert if starter kit files are created
- metadata apply
    - Assert server metadata after apply
    - assert that --dry-run flag will not modify metadata on server
- metadata clear
    - Assert with server metadata that operation was successful.
- metadata inconsistency drop
    - Assert with server metadata that operation was successful.
- metadata inconsistency status
    - Assert for all possible states
- metadata reload
    - Assert effect of operation with server
- migrate and seed subcommands
    - Add tests for MSSQL sources
    - Structure tests in such a way that it’s easy to add tests for new sources

https://github.com/hasura/graphql-engine-mono/pull/1693

Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: fcdbb806d105978a07487a40f7fa6e16b3ab8816
2021-07-28 06:45:03 +00:00

131 lines
4.3 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 commonMetadataCommandsTest = func(projectDirectory string) {
Context("check the behavior --dry-run", func() {
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"metadata", "apply", "--dry-run"},
WorkingDirectory: projectDirectory,
})
session := testutil.Hasura(testutil.CmdOpts{
Args: []string{"metadata", "diff"},
WorkingDirectory: projectDirectory,
})
Eventually(session, timeout).Should(Exit(0))
stdout := session.Out.Contents()
Expect(stdout).Should(ContainSubstring("tables"))
})
Context("should apply metadata to server", func() {
session := testutil.Hasura(testutil.CmdOpts{
Args: []string{"metadata", "apply"},
WorkingDirectory: projectDirectory,
})
Eventually(session, timeout).Should(Exit(0))
Expect(session.Err.Contents()).Should(ContainSubstring("Metadata applied"))
})
Context("apply metadata to server and it should output the metadata of project to stdout", func() {
projectSession := testutil.Hasura(testutil.CmdOpts{
Args: []string{"metadata", "apply", "--output", "json"},
WorkingDirectory: projectDirectory,
})
Eventually(projectSession, timeout).Should(Exit(0))
Eventually(isJSON(projectSession.Out.Contents())).Should(BeTrue())
projectStdout := projectSession.Out.Contents()
serverSession := testutil.Hasura(testutil.CmdOpts{
Args: []string{"metadata", "export", "--output", "json"},
WorkingDirectory: projectDirectory,
})
Eventually(serverSession, timeout).Should(Exit(0))
Eventually(isJSON(serverSession.Out.Contents())).Should(BeTrue())
serverStdout := serverSession.Out.Contents()
Expect(serverStdout).Should(MatchJSON(projectStdout))
})
}
var testConfigV2 = func(projectDirectory string) {
Context("apply migrations", func() {
testutil.RunCommandAndSucceed(testutil.CmdOpts{
Args: []string{"migrate", "apply"},
WorkingDirectory: projectDirectory,
})
})
commonMetadataCommandsTest(projectDirectory)
}
var _ = Describe("hasura metadata apply (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)
sourceName := randomdata.SillyName()
connectionString, teardownPG := testutil.StartPGContainer(GinkgoT())
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionString, sourceName)
copyTestConfigV3Project(projectDirectory)
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
editSourceNameInConfigV3ProjectTemplate(projectDirectory, sourceName, connectionString)
teardown = func() {
os.RemoveAll(projectDirectory)
teardownPG()
teardownHGE()
}
})
AfterEach(func() {
teardown()
})
It("metadata apply", func() {
commonMetadataCommandsTest(projectDirectory)
})
})
var _ = Describe("hasura metadata apply (config v2)", func() {
var projectDirectoryLatest, projectDirectoryV13 string
var teardown func()
BeforeEach(func() {
projectDirectoryLatest = testutil.RandDirName()
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
copyTestConfigV2Project(projectDirectoryLatest)
editEndpointInConfig(filepath.Join(projectDirectoryLatest, defaultConfigFilename), hgeEndpoint)
projectDirectoryV13 = testutil.RandDirName()
hgeEndPortV13, teardownHGEV13 := testutil.StartHasura(GinkgoT(), "hasura/graphql-engine:v1.3.3")
hgeEndpointV13 := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPortV13)
copyTestConfigV2Project(projectDirectoryV13)
editEndpointInConfig(filepath.Join(projectDirectoryV13, defaultConfigFilename), hgeEndpointV13)
teardown = func() {
os.RemoveAll(projectDirectoryLatest)
os.RemoveAll(projectDirectoryV13)
teardownHGE()
teardownHGEV13()
}
})
AfterEach(func() { teardown() })
It("metadata apply", func() {
testConfigV2(projectDirectoryLatest)
testConfigV2(projectDirectoryV13)
})
})