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 drop", 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()
|
|
|
|
connectionString, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
|
|
|
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)
|
2021-04-05 17:00:21 +03:00
|
|
|
teardownHGE()
|
2021-07-28 09:44:13 +03:00
|
|
|
teardownPG()
|
2021-04-05 17:00:21 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
AfterEach(func() { teardown() })
|
2021-04-05 17:00:21 +03:00
|
|
|
|
|
|
|
Context("metadata inconsistency drop test", func() {
|
|
|
|
It("Drops inconsistent objects from the metadata", func() {
|
2021-07-28 09:44:13 +03:00
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
|
|
Args: []string{"metadata", "apply"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
2021-06-03 16:26:28 +03:00
|
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
2021-07-28 09:44:13 +03:00
|
|
|
Args: []string{"metadata", "inconsistency", "status"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
|
|
|
Eventually(session, timeout).Should(Exit(1))
|
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring("metadata is inconsistent, use list command to see the objects"))
|
|
|
|
|
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
2021-04-05 17:00:21 +03:00
|
|
|
Args: []string{"metadata", "inconsistency", "drop"},
|
2021-07-28 09:44:13 +03:00
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
|
|
|
session = testutil.Hasura(testutil.CmdOpts{
|
|
|
|
Args: []string{"metadata", "inconsistency", "status"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
2021-07-28 09:44:13 +03:00
|
|
|
want := `metadata is consistent`
|
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|