2021-04-05 17:00:21 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
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 diff", func() {
|
2021-04-05 17:00:21 +03:00
|
|
|
|
2021-09-29 14:11:24 +03:00
|
|
|
var projectDirectory string
|
2021-04-05 17:00:21 +03:00
|
|
|
var teardown func()
|
|
|
|
BeforeEach(func() {
|
2021-09-29 14:11:24 +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)
|
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
2021-09-29 14:11:24 +03:00
|
|
|
Args: []string{"init", projectDirectory},
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
2021-09-29 14:11:24 +03:00
|
|
|
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
2021-04-05 17:00:21 +03:00
|
|
|
|
|
|
|
teardown = func() {
|
2021-09-29 14:11:24 +03:00
|
|
|
os.RemoveAll(projectDirectory)
|
2021-04-05 17:00:21 +03:00
|
|
|
teardownHGE()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
teardown()
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("metadata diff test", func() {
|
|
|
|
It("should output diff between metadata on server and local project", 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", "diff"},
|
2021-09-29 14:11:24 +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))
|
|
|
|
stdout := session.Out.Contents()
|
2021-12-09 20:25:54 +03:00
|
|
|
Expect(stdout).Should(ContainSubstring("kind: postgres"))
|
|
|
|
Expect(stdout).Should(ContainSubstring("name: default"))
|
2021-09-29 14:11:24 +03:00
|
|
|
|
|
|
|
editMetadataFileInConfig(filepath.Join(projectDirectory, defaultConfigFilename), "metadata.yaml")
|
|
|
|
session = testutil.Hasura(testutil.CmdOpts{
|
|
|
|
Args: []string{"metadata", "diff"},
|
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
|
|
stdout = session.Out.Contents()
|
2021-12-09 20:25:54 +03:00
|
|
|
Expect(stdout).Should(ContainSubstring("sources"))
|
|
|
|
Expect(stdout).Should(ContainSubstring("kind: postgres"))
|
|
|
|
Expect(stdout).Should(ContainSubstring("name: default"))
|
|
|
|
Expect(stdout).Should(ContainSubstring("tables: []"))
|
2021-09-29 14:11:24 +03:00
|
|
|
|
|
|
|
editMetadataFileInConfig(filepath.Join(projectDirectory, defaultConfigFilename), "metadata.json")
|
|
|
|
session = testutil.Hasura(testutil.CmdOpts{
|
2021-12-09 20:25:54 +03:00
|
|
|
Args: []string{"metadata", "diff", "--no-color"},
|
2021-09-29 14:11:24 +03:00
|
|
|
WorkingDirectory: projectDirectory,
|
|
|
|
})
|
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
|
|
|
stdout = session.Out.Contents()
|
|
|
|
want := `- "version": 3,
|
|
|
|
- "sources": [
|
|
|
|
- {
|
|
|
|
- "name": "default",
|
|
|
|
- "kind": "postgres",
|
|
|
|
- "tables": [],
|
|
|
|
- "configuration": {
|
|
|
|
`
|
|
|
|
|
|
|
|
Expect(stdout).Should(ContainSubstring(want))
|
2021-04-05 17:00:21 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|