2021-04-05 17:00:21 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-04-11 14:24:11 +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 clear", func() {
|
2021-04-05 17:00:21 +03:00
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
var projectDirectory 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()
|
2022-04-11 14:24:11 +03:00
|
|
|
t := GinkgoT()
|
|
|
|
|
|
|
|
sourceName := randomdata.SillyName()
|
|
|
|
connectionString, teardownPG := testutil.StartPGContainer(t)
|
|
|
|
|
|
|
|
hgeEndPort, teardownHGE := testutil.StartHasuraWithPG(t, testutil.HasuraDockerImage, connectionString)
|
2021-04-05 17:00:21 +03:00
|
|
|
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
2022-04-11 14:24:11 +03:00
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
copyTestConfigV3Project(projectDirectory)
|
|
|
|
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
2022-04-11 14:24:11 +03:00
|
|
|
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)
|
2022-04-11 14:24:11 +03:00
|
|
|
teardownPG()
|
2021-04-05 17:00:21 +03:00
|
|
|
teardownHGE()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
teardown()
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("metadata clear test", func() {
|
|
|
|
It("should clear metadata on server", 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-04-05 17:00:21 +03:00
|
|
|
Args: []string{"metadata", "clear"},
|
2021-07-28 09:44:13 +03:00
|
|
|
WorkingDirectory: projectDirectory,
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
2021-07-28 09:44:13 +03:00
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring("Metadata cleared"))
|
|
|
|
|
|
|
|
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"))
|
|
|
|
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|