mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-13 19:33:55 +03:00
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
This commit is contained in:
parent
5cfac6ea87
commit
ca567bf8cb
@ -74,7 +74,7 @@ test-e2e:
|
||||
ifndef HAS_GINKGO
|
||||
cd ~ && go get github.com/onsi/ginkgo/ginkgo && cd -
|
||||
endif
|
||||
cd commands && ginkgo -p -v --failFast
|
||||
cd commands && ginkgo -p -v -failFast
|
||||
|
||||
test-all: test integration_tests_config_v2 integration_tests_config_v3 test-e2e
|
||||
# clean the output directory
|
||||
|
@ -13,19 +13,19 @@ import (
|
||||
|
||||
var _ = Describe("hasura actions codegen", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
Args: []string{"init", projectDirectory},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownHGE()
|
||||
}
|
||||
})
|
||||
@ -36,14 +36,14 @@ var _ = Describe("hasura actions codegen", func() {
|
||||
It("creates the code for all actions specified framework and in directory as in config.yaml file", func() {
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"actions", "use-codegen", "--framework", "nodejs-express", "--output-dir", "codegen", "--with-starter-kit", "true"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"actions", "codegen"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Codegen files generated at codegen"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("Codegen files generated at codegen"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -61,9 +61,9 @@ var _ = Describe("actions_create", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session, 60*40).Should(Say(keyword))
|
||||
Eventually(session.Wait(timeout)).Should(Say(keyword))
|
||||
}
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -13,19 +14,19 @@ import (
|
||||
|
||||
var _ = Describe("hasura actions use-codegen", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
Args: []string{"init", projectDirectory},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownHGE()
|
||||
}
|
||||
})
|
||||
@ -36,17 +37,31 @@ var _ = Describe("hasura actions use-codegen", func() {
|
||||
It("should change the config.yaml file and create the nodejs-express directory ", func() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"actions", "use-codegen", "--framework", "nodejs-express", "--output-dir", "codegen", "--with-starter-kit", "true"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
wantKeywordList := []string{
|
||||
"Starter kit cloned at",
|
||||
"Codegen configuration updated in config.yaml",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents(), 60*40).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
configPath := filepath.Join(projectDirectory, "config.yaml")
|
||||
contents, err := ioutil.ReadFile(configPath)
|
||||
Expect(err).To(BeNil())
|
||||
wantKeywordList = []string{
|
||||
"framework: nodejs-express",
|
||||
"output_dir: codegen",
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(contents).Should(ContainSubstring(keyword))
|
||||
}
|
||||
|
||||
Expect(filepath.Join(projectDirectory, "nodejs-express")).To(BeADirectory())
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
|
||||
const (
|
||||
defaultConfigFilename = "config.yaml"
|
||||
timeout = testutil.DefaultE2ETestTimeout
|
||||
)
|
||||
|
||||
func TestE2e(t *testing.T) {
|
||||
|
@ -14,21 +14,45 @@ import (
|
||||
)
|
||||
|
||||
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, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Metadata applied"))
|
||||
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() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
projectSession := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "apply", "--output", "json"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(isJSON(session.Wait().Out.Contents())).Should(BeTrue())
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -13,19 +13,17 @@ import (
|
||||
|
||||
var _ = Describe("hasura metadata clear", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
copyTestConfigV3Project(projectDirectory)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownHGE()
|
||||
}
|
||||
})
|
||||
@ -36,12 +34,25 @@ var _ = Describe("hasura metadata clear", func() {
|
||||
|
||||
Context("metadata clear test", func() {
|
||||
It("should clear metadata on server", func() {
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "apply"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "clear"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Metadata cleared"))
|
||||
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"))
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,23 +1,23 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/projectmetadata"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"fmt"
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/projectmetadata"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/aryann/difflib"
|
||||
"github.com/aryann/difflib"
|
||||
|
||||
"github.com/hasura/graphql-engine/cli/v2"
|
||||
"github.com/hexops/gotextdiff"
|
||||
"github.com/hexops/gotextdiff/myers"
|
||||
"github.com/hexops/gotextdiff/span"
|
||||
"github.com/mgutz/ansi"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
"github.com/hasura/graphql-engine/cli/v2"
|
||||
"github.com/hexops/gotextdiff"
|
||||
"github.com/hexops/gotextdiff/myers"
|
||||
"github.com/hexops/gotextdiff/span"
|
||||
"github.com/mgutz/ansi"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type MetadataDiffOptions struct {
|
||||
|
@ -40,12 +40,13 @@ var _ = Describe("hasura metadata diff", func() {
|
||||
Args: []string{"metadata", "diff"},
|
||||
WorkingDirectory: dirName,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("-sources: []"))
|
||||
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("+sources:"))
|
||||
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("+ kind: postgres"))
|
||||
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("+ name: default"))
|
||||
Eventually(session.Wait().Out.Contents()).Should(ContainSubstring("+ tables: []"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
stdout := session.Out.Contents()
|
||||
Expect(stdout).Should(ContainSubstring("-sources: []"))
|
||||
Expect(stdout).Should(ContainSubstring("+sources:"))
|
||||
Expect(stdout).Should(ContainSubstring("+ kind: postgres"))
|
||||
Expect(stdout).Should(ContainSubstring("+ name: default"))
|
||||
Expect(stdout).Should(ContainSubstring("+ tables: []"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -19,16 +19,16 @@ var testExportMetadataToStdout = func(projectDirectory string) {
|
||||
Args: []string{"metadata", "export", "-o", "yaml"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
stdout := session.Wait().Out.Contents()
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
stdout := session.Out.Contents()
|
||||
Eventually(isYAML(stdout)).Should(BeTrue())
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "export", "--output", "json"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
stdout = session.Wait().Out.Contents()
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
stdout = session.Out.Contents()
|
||||
Eventually(isJSON(stdout)).Should(BeTrue())
|
||||
})
|
||||
}
|
||||
@ -42,8 +42,7 @@ var _ = Describe("hasura metadata export (config v3)", func() {
|
||||
hgeEndPort, teardownHGE := testutil.StartHasuraWithMetadataDatabase(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
|
||||
connectionString, teardownPG := testutil.StartPGContainer(GinkgoT())
|
||||
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionString, sourceName)
|
||||
connectionString, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
||||
|
||||
// clone template project directory as test project directory
|
||||
copyTestConfigV3Project(projectDirectory)
|
||||
@ -71,8 +70,8 @@ var _ = Describe("hasura metadata export (config v3)", func() {
|
||||
Args: []string{"metadata", "export"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Metadata exported"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("Metadata exported"))
|
||||
Expect(filepath.Join(projectDirectory, "metadata", "databases", sourceName, "tables", "public_albums.yaml")).Should(BeAnExistingFile())
|
||||
})
|
||||
testExportMetadataToStdout(projectDirectory)
|
||||
@ -112,8 +111,8 @@ var _ = Describe("hasura metadata export (config v2)", func() {
|
||||
Args: []string{"metadata", "export"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Metadata exported"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("Metadata exported"))
|
||||
Expect(filepath.Join(projectDirectory, "metadata", "tables.yaml")).Should(BeAnExistingFile())
|
||||
})
|
||||
testExportMetadataToStdout(projectDirectory)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
@ -13,20 +14,23 @@ import (
|
||||
|
||||
var _ = Describe("hasura metadata inconsistency drop", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var sourceName string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
sourceName = randomdata.SillyName()
|
||||
connectionString, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
||||
copyTestConfigV3Project(projectDirectory)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
editSourceNameInConfigV3ProjectTemplate(projectDirectory, sourceName, connectionString)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownHGE()
|
||||
teardownPG()
|
||||
}
|
||||
})
|
||||
|
||||
@ -34,13 +38,28 @@ var _ = Describe("hasura metadata inconsistency drop", func() {
|
||||
|
||||
Context("metadata inconsistency drop test", func() {
|
||||
It("Drops inconsistent objects from the metadata", func() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "drop"},
|
||||
WorkingDirectory: dirName,
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "apply"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want := `all inconsistent objects removed from metadata`
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(want))
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
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{
|
||||
Args: []string{"metadata", "inconsistency", "drop"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want := `metadata is consistent`
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -2,10 +2,10 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Pallinder/go-randomdata"
|
||||
"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"
|
||||
@ -19,10 +19,8 @@ var _ = Describe("hasura metadata inconsistency list", 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)
|
||||
connectionString, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
||||
copyTestConfigV3Project(projectDirectory)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
editSourceNameInConfigV3ProjectTemplate(projectDirectory, sourceName, connectionString)
|
||||
@ -53,16 +51,17 @@ var _ = Describe("hasura metadata inconsistency list", func() {
|
||||
Args: []string{"metadata", "inconsistency", "list"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
matcher(session.Wait().Out.Contents())
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
stdout := session.Out.Contents()
|
||||
matcher(stdout)
|
||||
})
|
||||
Context("Lists all inconsistent objects in json format", func() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "list", "-o", "json"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
stdout := session.Wait().Out.Contents()
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
stdout := session.Out.Contents()
|
||||
Eventually(isJSON(stdout)).Should(BeTrue())
|
||||
matcher(stdout)
|
||||
})
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
@ -13,19 +14,23 @@ import (
|
||||
|
||||
var _ = Describe("hasura metadata inconsistency status", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var sourceName string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
|
||||
sourceName = randomdata.SillyName()
|
||||
connectionString, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
||||
copyTestConfigV3Project(projectDirectory)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
editSourceNameInConfigV3ProjectTemplate(projectDirectory, sourceName, connectionString)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownPG()
|
||||
teardownHGE()
|
||||
}
|
||||
})
|
||||
@ -36,11 +41,27 @@ var _ = Describe("hasura metadata inconsistency status", func() {
|
||||
It("Checks if the metadata is inconsistent or not", func() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "status"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want := `metadata is consistent`
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(want))
|
||||
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,
|
||||
})
|
||||
want := `metadata is inconsistent, use list command to see the objects`
|
||||
Eventually(session.Wait(timeout)).Should(Exit(1))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -13,19 +13,17 @@ import (
|
||||
|
||||
var _ = Describe("hasura metadata reload", func() {
|
||||
|
||||
var dirName string
|
||||
var projectDirectory string
|
||||
var teardown func()
|
||||
BeforeEach(func() {
|
||||
dirName = testutil.RandDirName()
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", dirName},
|
||||
})
|
||||
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
||||
copyTestConfigV2Project(projectDirectory)
|
||||
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
||||
|
||||
teardown = func() {
|
||||
os.RemoveAll(dirName)
|
||||
os.RemoveAll(projectDirectory)
|
||||
teardownHGE()
|
||||
}
|
||||
})
|
||||
@ -36,11 +34,46 @@ var _ = Describe("hasura metadata reload", func() {
|
||||
It("should reload metadata", func() {
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "reload"},
|
||||
WorkingDirectory: dirName,
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want := `Metadata reloaded`
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(want))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
||||
})
|
||||
})
|
||||
|
||||
Context("metadata reload test incase of inconsistent metadata", func() {
|
||||
It("should reload the metadata on server and get inconsistent metadata", func() {
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "apply", "--up", "all"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "apply"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "apply", "--down", "all"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
session := testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want := `metadata is consistent`
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "reload"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"metadata", "inconsistency", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
want = `metadata is inconsistent, use list command to see the objects`
|
||||
Eventually(session.Wait(timeout)).Should(Exit(1))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(want))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -17,6 +17,30 @@ import (
|
||||
. "github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
func AddDatabaseToHasura(hgeEndpoint, sourceName, databaseKind string) (string, func()) {
|
||||
|
||||
if databaseKind == "postgres" {
|
||||
connectionStringPG, teardownPG := testutil.StartPGContainer(GinkgoT())
|
||||
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringPG, sourceName)
|
||||
return connectionStringPG, teardownPG
|
||||
}
|
||||
if databaseKind == "citus" {
|
||||
connectionStringCitus, teardownCitus := testutil.StartCitusContainer(GinkgoT())
|
||||
testutil.AddCitusSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringCitus, sourceName)
|
||||
return connectionStringCitus, teardownCitus
|
||||
}
|
||||
|
||||
if databaseKind == "mssql" {
|
||||
mssqlPort, teardownMSSQL := testutil.StartMSSQLContainer(GinkgoT())
|
||||
connectionStringMSSQL := fmt.Sprintf("DRIVER={ODBC Driver 17 for SQL Server};SERVER=%s,%s;DATABASE=master;Uid=SA;Pwd=%s;Encrypt=no", testutil.DockerSwitchIP, mssqlPort, testutil.MSSQLPassword)
|
||||
testutil.AddMSSQLSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringMSSQL, sourceName)
|
||||
return connectionStringMSSQL, teardownMSSQL
|
||||
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var testMigrateApply = func(projectDirectory string, globalFlags []string) {
|
||||
Context("migrate apply", func() {
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
@ -38,9 +62,9 @@ var testMigrateApply = func(projectDirectory string, globalFlags []string) {
|
||||
"applied",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -66,9 +90,9 @@ var testMigrateApplySkipExecution = func(projectDirectory string, globalFlags []
|
||||
"applied",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
@ -83,9 +107,9 @@ var testMigrateApplySkipExecution = func(projectDirectory string, globalFlags []
|
||||
"applied",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
@ -103,9 +127,9 @@ var testMigrateApplySkipExecution = func(projectDirectory string, globalFlags []
|
||||
".*Present Not Present*.",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Out, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Out).Should(Say(keyword))
|
||||
}
|
||||
|
||||
})
|
||||
@ -184,15 +208,14 @@ var _ = Describe("hasura migrate apply (config v3)", func() {
|
||||
var teardown func()
|
||||
var pgSource = randomdata.SillyName()
|
||||
var citusSource = randomdata.SillyName()
|
||||
var mssqlSource = randomdata.SillyName()
|
||||
BeforeEach(func() {
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasuraWithMetadataDatabase(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint = fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
connectionStringPG, teardownPG := testutil.StartPGContainer(GinkgoT())
|
||||
connectionStringCitus, teardownCitus := testutil.StartCitusContainer(GinkgoT())
|
||||
// add a pg source named default
|
||||
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringPG, pgSource)
|
||||
testutil.AddCitusSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringCitus, citusSource)
|
||||
_, teardownPG := AddDatabaseToHasura(hgeEndpoint, pgSource, "postgres")
|
||||
_, teardownCitus := AddDatabaseToHasura(hgeEndpoint, citusSource, "citus")
|
||||
_, teardownMSSQL := AddDatabaseToHasura(hgeEndpoint, mssqlSource, "mssql")
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", projectDirectory},
|
||||
})
|
||||
@ -202,13 +225,15 @@ var _ = Describe("hasura migrate apply (config v3)", func() {
|
||||
teardownHGE()
|
||||
teardownPG()
|
||||
teardownCitus()
|
||||
teardownMSSQL()
|
||||
}
|
||||
})
|
||||
AfterEach(func() { teardown() })
|
||||
|
||||
It("should apply the migrations on server ", func() {
|
||||
It("should apply the migrations on server", func() {
|
||||
testMigrateApply(projectDirectory, []string{"--database-name", pgSource})
|
||||
testMigrateApply(projectDirectory, []string{"--database-name", citusSource})
|
||||
testMigrateApply(projectDirectory, []string{"--database-name", mssqlSource})
|
||||
})
|
||||
It("should mark the migrations as applied ", func() {
|
||||
testMigrateApplySkipExecution(projectDirectory, []string{"--database-name", pgSource})
|
||||
|
@ -53,9 +53,9 @@ var _ = Describe("hasura migrate create (config v3)", func() {
|
||||
"version",
|
||||
}
|
||||
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", "default"))
|
||||
Expect(err).To(BeNil())
|
||||
@ -87,9 +87,9 @@ var _ = Describe("hasura migrate create (config v3)", func() {
|
||||
"version",
|
||||
}
|
||||
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", sourceName))
|
||||
Expect(err).To(BeNil())
|
||||
@ -150,9 +150,9 @@ var _ = Describe("hasura migrate create (config v2)", func() {
|
||||
},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
|
||||
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations"))
|
||||
|
@ -54,7 +54,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
@ -62,7 +62,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
|
||||
Eventually(session.Err, 60*40).Should(Say("--database-name flag is required"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("--database-name flag is required"))
|
||||
|
||||
args := strings.Join([]string{"yes", "|", testutil.CLIBinaryPath, "migrate", "delete", "--all", "--database-name", "default"}, " ")
|
||||
cmd := exec.Command("bash", "-c", args)
|
||||
@ -73,14 +73,14 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
NewPrefixedWriter(testutil.DebugErrPrefix, GinkgoWriter),
|
||||
)
|
||||
Expect(err).To(BeNil())
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status", "--database-name", "default"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Err, 60*40).ShouldNot(Say(version))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Expect(session.Wait(timeout).Err).ShouldNot(Say(version))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
@ -111,7 +111,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
@ -119,7 +119,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
|
||||
Eventually(session.Err, 60*40).Should(Say("--database-name flag is required"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("--database-name flag is required"))
|
||||
|
||||
args := strings.Join([]string{"yes", "|", testutil.CLIBinaryPath, "migrate", "delete", "--all", "--server", "--database-name", "default"}, " ")
|
||||
cmd := exec.Command("bash", "-c", args)
|
||||
@ -130,16 +130,16 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
NewPrefixedWriter(testutil.DebugErrPrefix, GinkgoWriter),
|
||||
)
|
||||
Expect(err).To(BeNil())
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status", "--database-name", "default"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Out, 60*40).Should(Say(version))
|
||||
Eventually(session.Out, 60*40).Should(Say("Present"))
|
||||
Eventually(session.Out, 60*40).Should(Say("Not Present"))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Eventually(session.Out).Should(Say(version))
|
||||
Eventually(session.Out).Should(Say("Present"))
|
||||
Eventually(session.Out).Should(Say("Not Present"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
@ -170,21 +170,21 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "delete", "--version", version, "--database-name", "default"},
|
||||
WorkingDirectory: dirName,
|
||||
})
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status", "--database-name", "default"},
|
||||
WorkingDirectory: dirName,
|
||||
})
|
||||
Eventually(session.Err, 60*40).ShouldNot(Say(version))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Expect(session.Wait(timeout).Err).ShouldNot(Say(version))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
@ -215,21 +215,21 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "delete", "--version", version},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Err, 60*40).ShouldNot(Say(version))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Expect(session.Wait(timeout).Err).ShouldNot(Say(version))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
@ -260,7 +260,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
args := []string{"migrate", "delete", "--all", "--force"}
|
||||
@ -272,14 +272,14 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
NewPrefixedWriter(testutil.DebugErrPrefix, GinkgoWriter),
|
||||
)
|
||||
Expect(err).To(BeNil())
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Err, 60*40).ShouldNot(Say(version))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Expect(session.Wait(timeout).Err).ShouldNot(Say(version))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
@ -310,7 +310,7 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Err, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Err).Should(Say(keyword))
|
||||
}
|
||||
|
||||
args := []string{"migrate", "delete", "--all", "--server", "--force"}
|
||||
@ -322,16 +322,16 @@ var _ = Describe("hasura migrate delete", func() {
|
||||
NewPrefixedWriter(testutil.DebugErrPrefix, GinkgoWriter),
|
||||
)
|
||||
Expect(err).To(BeNil())
|
||||
Eventually(session.Err, 60*40).Should(Say("Deleted migrations"))
|
||||
Expect(session.Wait(timeout).Err).Should(Say("Deleted migrations"))
|
||||
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "status"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session.Out, 60*40).Should(Say(version))
|
||||
Eventually(session.Out, 60*40).Should(Say("Present"))
|
||||
Eventually(session.Out, 60*40).Should(Say("Not Present"))
|
||||
Eventually(session, 60*50).Should(Exit(0))
|
||||
Expect(session.Wait(timeout).Out).Should(Say(version))
|
||||
Expect(session.Wait(timeout).Out).Should(Say("Present"))
|
||||
Expect(session.Wait(timeout).Out).Should(Say("Not Present"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -27,8 +27,8 @@ var _ = Describe("hasura migrate squash (config v3)", func() {
|
||||
}, globalFlags...),
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
logs := string(session.Wait().Err.Contents())
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
logs := string(session.Err.Contents())
|
||||
version := regexp.MustCompile(`"version":\d+`)
|
||||
matches := version.FindStringSubmatch(logs)
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
@ -48,9 +48,9 @@ var _ = Describe("hasura migrate squash (config v3)", func() {
|
||||
"till",
|
||||
}
|
||||
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
||||
}
|
||||
// verify files were deleted
|
||||
v := strings.Split(matches[0], ":")[1]
|
||||
@ -60,7 +60,7 @@ var _ = Describe("hasura migrate squash (config v3)", func() {
|
||||
Args: append([]string{"migrate", "status"}, globalFlags...),
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Eventually(session.Out.Contents()).ShouldNot(ContainSubstring(v))
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,9 @@ var _ = Describe("hasura migrate status", func() {
|
||||
}
|
||||
|
||||
for _, keyword := range wantKeywordList {
|
||||
Eventually(session.Out, 60*40).Should(Say(keyword))
|
||||
Expect(session.Wait(timeout).Out).Should(Say(keyword))
|
||||
}
|
||||
Eventually(session, 60*40).Should(Exit(0))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -114,7 +114,6 @@ func (p *pluginListOptions) run() error {
|
||||
return printTable(p.EC.Stdout, cols, rows)
|
||||
}
|
||||
|
||||
|
||||
func printTable(out io.Writer, columns []string, rows [][]string) error {
|
||||
w := tabwriter.NewWriter(out, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprint(w, strings.Join(columns, "\t"))
|
||||
|
@ -89,7 +89,7 @@ var _ = Describe("hasura scripts update-project-v3", func() {
|
||||
})
|
||||
|
||||
Eventually(session.Err, 60).Should(Say(`.*error.*`))
|
||||
Eventually(session, 60*4).Should(Exit())
|
||||
Eventually(session.Wait(timeout)).Should(Exit())
|
||||
})
|
||||
|
||||
Context("applies metadata and migrations on staging hasura instance", func() {
|
||||
@ -101,16 +101,16 @@ var _ = Describe("hasura scripts update-project-v3", func() {
|
||||
Args: []string{"migrate", "apply", "--database-name", "default", "--endpoint", stagingEndpoint},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*4).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("nothing to apply"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("nothing to apply"))
|
||||
|
||||
// This now should not trigger a state migration
|
||||
session = testutil.Hasura(testutil.CmdOpts{
|
||||
Args: []string{"migrate", "apply", "--database-name", "default", "--endpoint", stagingEndpoint, "--log-level", "debug"},
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*4).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(`{"level":"debug","msg":"skipping state migration, found IsStateCopyCompleted: true Migrations: map[default:map[1620138136207:false 1620138146208:false 1620138161039:false 1620138169404:false 1620138179776:false 1620138189381:false 1620138199344:false]]"`))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring(`{"level":"debug","msg":"skipping state migration, found IsStateCopyCompleted: true Migrations: map[default:map[1620138136207:false 1620138146208:false 1620138161039:false 1620138169404:false 1620138179776:false 1620138189381:false 1620138199344:false]]"`))
|
||||
})
|
||||
Context("applies metadata and migrations on production hasura instance", func() {
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
@ -133,8 +133,8 @@ var _ = Describe("hasura scripts update-project-v3", func() {
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
|
||||
Eventually(session, 60*4).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("nothing to apply"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("nothing to apply"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -14,9 +14,16 @@ import (
|
||||
. "github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var test = func(projectDirectory string, globalFlags []string) {
|
||||
upSql := `CREATE TABLE "public"."table1" ("id" serial NOT NULL, PRIMARY KEY ("id") );`
|
||||
downSql := `DROP TABLE "public"."table1";`
|
||||
var test = func(projectDirectory string, globalFlags []string, databaseKind string) {
|
||||
var upSql, downSql string
|
||||
if databaseKind == "mssql" {
|
||||
upSql = `CREATE SCHEMA test` + "\n" + `CREATE TABLE "test"."table1" ("id" int NOT NULL, PRIMARY KEY ("id") );`
|
||||
downSql = `DROP TABLE "test"."table1";` + "\n" + `DROP SCHEMA test`
|
||||
} else {
|
||||
upSql = `CREATE TABLE "public"."table1" ("id" serial NOT NULL, PRIMARY KEY ("id") );`
|
||||
downSql = `DROP TABLE "public"."table1";`
|
||||
}
|
||||
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: append([]string{"migrate", "create", "table1", "--up-sql", upSql, "--down-sql", downSql}, globalFlags...),
|
||||
WorkingDirectory: projectDirectory,
|
||||
@ -29,8 +36,8 @@ var test = func(projectDirectory string, globalFlags []string) {
|
||||
Args: append([]string{"seed", "apply", "--file", "table_seed.sql"}, globalFlags...),
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Seeds planted"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("Seeds planted"))
|
||||
}
|
||||
|
||||
var _ = Describe("seed apply (config v2)", func() {
|
||||
@ -66,7 +73,7 @@ var _ = Describe("seed apply (config v2)", func() {
|
||||
|
||||
_, err = file.WriteString(data)
|
||||
Expect(err).To(BeNil())
|
||||
test(projectDirectoryConfigV2, nil)
|
||||
test(projectDirectoryConfigV2, nil, "postgres")
|
||||
})
|
||||
})
|
||||
|
||||
@ -76,15 +83,14 @@ var _ = Describe("seed apply (config v3)", func() {
|
||||
var teardown func()
|
||||
var pgSource = randomdata.SillyName()
|
||||
var citusSource = randomdata.SillyName()
|
||||
var mssqlSource = randomdata.SillyName()
|
||||
BeforeEach(func() {
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasuraWithMetadataDatabase(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
connectionStringPG, teardownPG := testutil.StartPGContainer(GinkgoT())
|
||||
connectionStringCitus, teardownCitus := testutil.StartCitusContainer(GinkgoT())
|
||||
// add a pg source named default
|
||||
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringPG, pgSource)
|
||||
testutil.AddCitusSourceToHasura(GinkgoT(), hgeEndpoint, connectionStringCitus, citusSource)
|
||||
_, teardownPG := AddDatabaseToHasura(hgeEndpoint, pgSource, "postgres")
|
||||
_, teardownCitus := AddDatabaseToHasura(hgeEndpoint, citusSource, "citus")
|
||||
_, teardownMSSQL := AddDatabaseToHasura(hgeEndpoint, mssqlSource, "mssql")
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", projectDirectory},
|
||||
})
|
||||
@ -94,6 +100,7 @@ var _ = Describe("seed apply (config v3)", func() {
|
||||
teardownHGE()
|
||||
teardownPG()
|
||||
teardownCitus()
|
||||
teardownMSSQL()
|
||||
}
|
||||
})
|
||||
AfterEach(func() { teardown() })
|
||||
@ -106,16 +113,26 @@ var _ = Describe("seed apply (config v3)", func() {
|
||||
INSERT INTO public.table1 (id) VALUES (3);
|
||||
INSERT INTO public.table1 (id) VALUES (4);`)
|
||||
|
||||
mssqlData := []byte(`INSERT INTO "test"."table1" (id) VALUES (1);
|
||||
INSERT INTO "test"."table1" (id) VALUES (2);
|
||||
INSERT INTO "test"."table1" (id) VALUES (3);
|
||||
INSERT INTO "test"."table1" (id) VALUES (4);`)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(projectDirectory, "seeds", pgSource, "table_seed.sql"), data, 0655)
|
||||
Expect(err).To(BeNil())
|
||||
test(projectDirectory, []string{"--database-name", pgSource})
|
||||
test(projectDirectory, []string{"--database-name", pgSource}, "postgres")
|
||||
|
||||
err = os.MkdirAll(filepath.Join(filepath.Join(projectDirectory, "seeds", citusSource)), 0755)
|
||||
Expect(err).To(BeNil())
|
||||
err = ioutil.WriteFile(filepath.Join(projectDirectory, "seeds", citusSource, "table_seed.sql"), data, 0655)
|
||||
Expect(err).To(BeNil())
|
||||
test(projectDirectory, []string{"--database-name", citusSource}, "citus")
|
||||
|
||||
err = os.MkdirAll(filepath.Join(filepath.Join(projectDirectory, "seeds", mssqlSource)), 0755)
|
||||
Expect(err).To(BeNil())
|
||||
test(projectDirectory, []string{"--database-name", citusSource})
|
||||
err = ioutil.WriteFile(filepath.Join(projectDirectory, "seeds", mssqlSource, "table_seed.sql"), mssqlData, 0655)
|
||||
Expect(err).To(BeNil())
|
||||
test(projectDirectory, []string{"--database-name", mssqlSource}, "mssql")
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -34,8 +34,8 @@ var testSeedCreate = func(projectDirectory string, globalFlags []string) {
|
||||
Args: append([]string{"seed", "create", "table_seed", "--from-table", "table1"}, globalFlags...),
|
||||
WorkingDirectory: projectDirectory,
|
||||
})
|
||||
Eventually(session, 60*60).Should(Exit(0))
|
||||
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("created seed file successfully"))
|
||||
Eventually(session, timeout).Should(Exit(0))
|
||||
Expect(session.Err.Contents()).Should(ContainSubstring("created seed file successfully"))
|
||||
}
|
||||
|
||||
var _ = Describe("hasura seed create", func() {
|
||||
@ -47,10 +47,8 @@ var _ = Describe("hasura seed create", func() {
|
||||
projectDirectory = testutil.RandDirName()
|
||||
hgeEndPort, teardownHGE := testutil.StartHasuraWithMetadataDatabase(GinkgoT(), testutil.HasuraDockerImage)
|
||||
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
||||
|
||||
connectionUrl, teardownPG := testutil.StartPGContainer(GinkgoT())
|
||||
sourceName = randomdata.SillyName()
|
||||
testutil.AddPGSourceToHasura(GinkgoT(), hgeEndpoint, connectionUrl, sourceName)
|
||||
_, teardownPG := AddDatabaseToHasura(hgeEndpoint, sourceName, "postgres")
|
||||
|
||||
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
||||
Args: []string{"init", projectDirectory},
|
||||
|
@ -20,6 +20,7 @@ const (
|
||||
DebugCommandPrefixWithDir = "\nCMD %s>"
|
||||
DebugOutPrefix = "OUT: "
|
||||
DebugErrPrefix = "ERR: "
|
||||
DefaultE2ETestTimeout = 60 // in seconds
|
||||
)
|
||||
|
||||
type CmdOpts struct {
|
||||
@ -29,7 +30,8 @@ type CmdOpts struct {
|
||||
|
||||
func Hasura(opts CmdOpts) *Session {
|
||||
var hasuraBinaryPath = CLIBinaryPath
|
||||
cmd := exec.Command(hasuraBinaryPath, opts.Args...)
|
||||
args := append([]string{"--skip-update-check"}, opts.Args...)
|
||||
cmd := exec.Command(hasuraBinaryPath, args...)
|
||||
if opts.WorkingDirectory != "" {
|
||||
cmd.Dir = opts.WorkingDirectory
|
||||
}
|
||||
@ -43,7 +45,7 @@ func Hasura(opts CmdOpts) *Session {
|
||||
}
|
||||
func RunCommandAndSucceed(opts CmdOpts) *Session {
|
||||
session := Hasura(opts)
|
||||
Eventually(session, 5).Should(Exit(0))
|
||||
Eventually(session, DefaultE2ETestTimeout).Should(Exit(0))
|
||||
return session
|
||||
}
|
||||
|
||||
@ -83,3 +85,18 @@ func RemoveHasuraConfigHomeDirectory() {
|
||||
err = os.RemoveAll(filepath.Join(homeDir, ".hasura"))
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
}
|
||||
|
||||
// to run commands other than hasura
|
||||
func Command(cmdPath string, opts CmdOpts) *Session {
|
||||
cmd := exec.Command(cmdPath, opts.Args...)
|
||||
if opts.WorkingDirectory != "" {
|
||||
cmd.Dir = opts.WorkingDirectory
|
||||
}
|
||||
session, err := Start(
|
||||
cmd,
|
||||
NewPrefixedWriter(DebugOutPrefix, GinkgoWriter),
|
||||
NewPrefixedWriter(DebugErrPrefix, GinkgoWriter),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
return session
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
|
||||
"github.com/Pallinder/go-randomdata"
|
||||
"github.com/gofrs/uuid"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/Pallinder/go-randomdata"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
// helper function to get image repo and tag separately
|
||||
@ -48,20 +48,20 @@ type TestingT interface {
|
||||
func StartHasura(t TestingT, image string) (port string, teardown func()) {
|
||||
connectionUrl, teardownPG := StartPGContainer(t)
|
||||
port, teardownHasura := StartHasuraWithPG(t, image, connectionUrl)
|
||||
return port, func() {teardownHasura(); teardownPG()}
|
||||
return port, func() { teardownHasura(); teardownPG() }
|
||||
}
|
||||
|
||||
func StartHasuraCLIMigrations(t TestingT, image string, pgConnectionUrl string, metadataDir, migrationsDir string) (port string, teardown func()) {
|
||||
port, teardownHasura := StartHasuraWithPG(t, image, pgConnectionUrl, func(o *docker.HostConfig) {
|
||||
o.Binds = []string{}
|
||||
if len(metadataDir) > 0 {
|
||||
o.Binds = append(o.Binds, fmt.Sprintf("%s:%s", metadataDir, "/hasura-metadata"))
|
||||
}
|
||||
if len(migrationsDir) > 0 {
|
||||
o.Binds = append(o.Binds, fmt.Sprintf("%s:%s", migrationsDir, "/hasura-migrations"))
|
||||
}
|
||||
})
|
||||
return port, func() {teardownHasura()}
|
||||
port, teardownHasura := StartHasuraWithPG(t, image, pgConnectionUrl, func(o *docker.HostConfig) {
|
||||
o.Binds = []string{}
|
||||
if len(metadataDir) > 0 {
|
||||
o.Binds = append(o.Binds, fmt.Sprintf("%s:%s", metadataDir, "/hasura-metadata"))
|
||||
}
|
||||
if len(migrationsDir) > 0 {
|
||||
o.Binds = append(o.Binds, fmt.Sprintf("%s:%s", migrationsDir, "/hasura-migrations"))
|
||||
}
|
||||
})
|
||||
return port, func() { teardownHasura() }
|
||||
}
|
||||
|
||||
func StartHasuraWithPG(t TestingT, image string, pgConnectionUrl string, dockerOpts ...func(*docker.HostConfig)) (port string, teardown func()) {
|
||||
@ -204,19 +204,19 @@ func StartHasuraWithMetadataDatabase(t TestingT, image string) (port string, tea
|
||||
func StartHasuraWithMSSQLSource(t *testing.T, version string) (string, string, func()) {
|
||||
hasuraPort, hasuraTeardown := StartHasuraWithMetadataDatabase(t, version)
|
||||
sourcename := randomdata.SillyName()
|
||||
mssqlPort, mssqlTeardown := startMSSQLContainer(t)
|
||||
mssqlPort, mssqlTeardown := StartMSSQLContainer(t)
|
||||
|
||||
teardown := func() {
|
||||
hasuraTeardown()
|
||||
mssqlTeardown()
|
||||
}
|
||||
connectionString := fmt.Sprintf("DRIVER={ODBC Driver 17 for SQL Server};SERVER=%s,%s;DATABASE=master;Uid=SA;Pwd=%s;Encrypt=no", DockerSwitchIP, mssqlPort, MSSQLPassword)
|
||||
addMSSQLSourceToHasura(t, fmt.Sprintf("%s:%s", BaseURL, hasuraPort), connectionString, sourcename)
|
||||
AddMSSQLSourceToHasura(t, fmt.Sprintf("%s:%s", BaseURL, hasuraPort), connectionString, sourcename)
|
||||
return hasuraPort, sourcename, teardown
|
||||
}
|
||||
|
||||
// startsMSSQLContainer and creates a database and returns the port number
|
||||
func startMSSQLContainer(t *testing.T) (string, func()) {
|
||||
func StartMSSQLContainer(t TestingT) (string, func()) {
|
||||
pool, err := dockertest.NewPool("")
|
||||
pool.MaxWait = time.Minute
|
||||
if err != nil {
|
||||
@ -305,7 +305,7 @@ func StartPGContainer(t TestingT) (connectionString string, teardown func()) {
|
||||
return connectionString, teardown
|
||||
}
|
||||
|
||||
func addMSSQLSourceToHasura(t *testing.T, hasuraEndpoint, connectionString, sourceName string) {
|
||||
func AddMSSQLSourceToHasura(t TestingT, hasuraEndpoint, connectionString, sourceName string) {
|
||||
url := fmt.Sprintf("%s/v1/metadata", hasuraEndpoint)
|
||||
body := fmt.Sprintf(`
|
||||
{
|
||||
@ -324,7 +324,9 @@ func addMSSQLSourceToHasura(t *testing.T, hasuraEndpoint, connectionString, sour
|
||||
fmt.Println(hasuraEndpoint)
|
||||
|
||||
req, err := http.NewRequest("POST", url, strings.NewReader(body))
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
adminSecret := os.Getenv("HASURA_GRAPHQL_TEST_ADMIN_SECRET")
|
||||
if adminSecret != "" {
|
||||
@ -332,7 +334,9 @@ func addMSSQLSourceToHasura(t *testing.T, hasuraEndpoint, connectionString, sour
|
||||
}
|
||||
|
||||
r, err := http.DefaultClient.Do(req)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
||||
)
|
||||
|
||||
func NewTableWriter(w io.Writer) *tablewriter.Table {
|
||||
|
Loading…
Reference in New Issue
Block a user