2021-04-05 17:00:21 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
"github.com/Pallinder/go-randomdata"
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
2021-04-05 17:00:21 +03:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
. "github.com/onsi/gomega/gexec"
|
|
|
|
)
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
var _ = Describe("hasura metadata inconsistency status", func() {
|
2021-04-05 17:00:21 +03:00
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
var projectDirectory string
|
|
|
|
var sourceName string
|
2021-04-05 17:00:21 +03:00
|
|
|
var teardown func()
|
|
|
|
BeforeEach(func() {
|
2021-07-28 09:44:13 +03:00
|
|
|
projectDirectory = testutil.RandDirName()
|
2021-06-03 16:26:28 +03:00
|
|
|
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
2021-04-05 17:00:21 +03:00
|
|
|
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
2021-07-28 09:44:13 +03:00
|
|
|
|
|
|
|
sourceName = randomdata.SillyName()
|
2022-09-27 14:15:09 +03:00
|
|
|
connectionString, teardownPG := testutil.AddDatabaseToHasura(GinkgoT(), hgeEndpoint, sourceName, "postgres")
|
2021-07-28 09:44:13 +03:00
|
|
|
copyTestConfigV3Project(projectDirectory)
|
|
|
|
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
|
|
|
editSourceNameInConfigV3ProjectTemplate(projectDirectory, sourceName, connectionString)
|
2021-04-05 17:00:21 +03:00
|
|
|
|
|
|
|
teardown = func() {
|
2021-07-28 09:44:13 +03:00
|
|
|
os.RemoveAll(projectDirectory)
|
|
|
|
teardownPG()
|
2021-04-05 17:00:21 +03:00
|
|
|
teardownHGE()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
AfterEach(func() { teardown() })
|
2021-04-05 17:00:21 +03:00
|
|
|
|
|
|
|
Context("metadata inconsistency status test", func() {
|
|
|
|
It("Checks if the metadata is inconsistent or not", func() {
|
2021-06-03 16:26:28 +03:00
|
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
2021-04-05 17:00:21 +03:00
|
|
|
Args: []string{"metadata", "inconsistency", "status"},
|
2021-07-28 09:44:13 +03:00
|
|
|
WorkingDirectory: projectDirectory,
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
2021-05-14 22:09:01 +03:00
|
|
|
want := `metadata is consistent`
|
2021-07-28 09:44:13 +03:00
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("metadata inconsistency status test incase of inconsistent metadata", func() {
|
|
|
|
It("Checks if the metadata is inconsistent or not", func() {
|
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
|
|
Args: []string{"metadata", "apply"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
|
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
|
|
|
Args: []string{"metadata", "inconsistency", "status"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
2021-10-08 19:09:30 +03:00
|
|
|
want := `metadata is inconsistent, use 'hasura metadata ic list' command to see the inconsistent objects`
|
2021-07-28 09:44:13 +03:00
|
|
|
Eventually(session.Wait(timeout)).Should(Exit(1))
|
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|