mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
3136ffad1b
> ### Description Update `go.mod` to allow other packages to import [v2.0.0 versions](https://blog.golang.org/v2-go-modules). ### Changelog - [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ### Affected components - [x] CLI https://github.com/hasura/graphql-engine-mono/pull/1584 GitOrigin-RevId: a5d17ad20289d1cd7217763f56ef3ba6552d69c4
133 lines
3.9 KiB
Go
133 lines
3.9 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
. "github.com/onsi/gomega/gexec"
|
|
)
|
|
|
|
var _ = Describe("hasura migrate create (config v3)", func() {
|
|
var projectDirectory string
|
|
var teardown func()
|
|
BeforeEach(func() {
|
|
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", projectDirectory},
|
|
})
|
|
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
|
|
|
teardown = func() {
|
|
os.RemoveAll(projectDirectory)
|
|
teardownHGE()
|
|
}
|
|
})
|
|
|
|
AfterEach(func() { teardown() })
|
|
|
|
It("can create migrations for default database", func() {
|
|
migrationName := "create_schema_testing"
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
|
Args: []string{
|
|
"migrate",
|
|
"create",
|
|
migrationName,
|
|
"--up-sql",
|
|
"create schema \"testing\";",
|
|
"--down-sql",
|
|
"drop schema \"testing\" cascade;",
|
|
"--database-name", "default",
|
|
},
|
|
WorkingDirectory: projectDirectory,
|
|
})
|
|
wantKeywordList := []string{
|
|
"Migrations files created",
|
|
migrationName,
|
|
"version",
|
|
}
|
|
|
|
Eventually(session, 60*60).Should(Exit(0))
|
|
for _, keyword := range wantKeywordList {
|
|
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
|
}
|
|
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations", "default"))
|
|
Expect(err).To(BeNil())
|
|
for _, d := range dirs {
|
|
Expect(d.Name()).Should(ContainSubstring(migrationName))
|
|
}
|
|
})
|
|
})
|
|
|
|
var _ = Describe("hasura migrate create (config v2)", func() {
|
|
var projectDirectoryLatest, projectDirectoryV13 string
|
|
var session *Session
|
|
var teardown func()
|
|
BeforeEach(func() {
|
|
projectDirectoryLatest = testutil.RandDirName()
|
|
hgeEndPortLatest, teardownHGELatest := testutil.StartHasura(GinkgoT(), testutil.HasuraDockerImage)
|
|
hgeEndpointLatest := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPortLatest)
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
Args: []string{"init", projectDirectoryLatest, "--version", "2"},
|
|
})
|
|
editEndpointInConfig(filepath.Join(projectDirectoryLatest, defaultConfigFilename), hgeEndpointLatest)
|
|
|
|
projectDirectoryV13 = testutil.RandDirName()
|
|
hgeEndPortV13, teardownHGEV13 := testutil.StartHasura(GinkgoT(), "hasura/graphql-engine:v1.3.3")
|
|
hgeEndpointV13 := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPortV13)
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
Args: []string{"init", projectDirectoryV13, "--version", "2"},
|
|
})
|
|
editEndpointInConfig(filepath.Join(projectDirectoryV13, defaultConfigFilename), hgeEndpointV13)
|
|
|
|
teardown = func() {
|
|
session.Kill()
|
|
os.RemoveAll(projectDirectoryLatest)
|
|
os.RemoveAll(projectDirectoryV13)
|
|
teardownHGEV13()
|
|
teardownHGELatest()
|
|
}
|
|
})
|
|
|
|
AfterEach(func() { teardown() })
|
|
|
|
It("can create migration files", func() {
|
|
test := func(projectDirectory string) {
|
|
migrationName := "create_schema_testing"
|
|
wantKeywordList := []string{
|
|
"Migrations files created",
|
|
migrationName,
|
|
"version",
|
|
}
|
|
session = testutil.Hasura(testutil.CmdOpts{
|
|
Args: []string{
|
|
"migrate",
|
|
"create",
|
|
migrationName,
|
|
"--up-sql", "create schema \"testing\";",
|
|
"--down-sql",
|
|
"drop schema \"testing\" cascade;",
|
|
},
|
|
WorkingDirectory: projectDirectory,
|
|
})
|
|
Eventually(session, 60*60).Should(Exit(0))
|
|
for _, keyword := range wantKeywordList {
|
|
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring(keyword))
|
|
}
|
|
|
|
dirs, err := os.ReadDir(filepath.Join(projectDirectory, "migrations"))
|
|
Expect(err).To(BeNil())
|
|
for _, d := range dirs {
|
|
Expect(d.Name()).Should(ContainSubstring(migrationName))
|
|
}
|
|
}
|
|
test(projectDirectoryLatest)
|
|
test(projectDirectoryV13)
|
|
})
|
|
})
|