2021-04-13 11:22:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-28 09:44:13 +03:00
|
|
|
"io/ioutil"
|
2021-04-13 11:22:48 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
2021-04-13 11:22:48 +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 actions use-codegen", func() {
|
2021-04-13 11:22:48 +03:00
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
var projectDirectory string
|
2021-04-13 11:22:48 +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-13 11:22:48 +03:00
|
|
|
hgeEndpoint := fmt.Sprintf("http://0.0.0.0:%s", hgeEndPort)
|
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
2021-07-28 09:44:13 +03:00
|
|
|
Args: []string{"init", projectDirectory},
|
2021-04-13 11:22:48 +03:00
|
|
|
})
|
2021-07-28 09:44:13 +03:00
|
|
|
editEndpointInConfig(filepath.Join(projectDirectory, defaultConfigFilename), hgeEndpoint)
|
2021-04-13 11:22:48 +03:00
|
|
|
|
|
|
|
teardown = func() {
|
2021-07-28 09:44:13 +03:00
|
|
|
os.RemoveAll(projectDirectory)
|
2021-04-13 11:22:48 +03:00
|
|
|
teardownHGE()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
AfterEach(func() { teardown() })
|
2021-04-13 11:22:48 +03:00
|
|
|
|
|
|
|
Context("actions use codegen tests", func() {
|
|
|
|
It("should change the config.yaml file and create the nodejs-express directory ", func() {
|
2021-06-03 16:26:28 +03:00
|
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
2021-04-13 11:22:48 +03:00
|
|
|
Args: []string{"actions", "use-codegen", "--framework", "nodejs-express", "--output-dir", "codegen", "--with-starter-kit", "true"},
|
2021-07-28 09:44:13 +03:00
|
|
|
WorkingDirectory: projectDirectory,
|
2021-04-13 11:22:48 +03:00
|
|
|
})
|
|
|
|
wantKeywordList := []string{
|
2021-05-14 22:09:01 +03:00
|
|
|
"Starter kit cloned at",
|
|
|
|
"Codegen configuration updated in config.yaml",
|
2021-04-13 11:22:48 +03:00
|
|
|
}
|
|
|
|
|
2021-07-28 09:44:13 +03:00
|
|
|
Eventually(session, timeout).Should(Exit(0))
|
2021-04-13 11:22:48 +03:00
|
|
|
for _, keyword := range wantKeywordList {
|
2021-07-28 09:44:13 +03:00
|
|
|
Expect(session.Err.Contents()).Should(ContainSubstring(keyword))
|
2021-04-13 11:22:48 +03:00
|
|
|
}
|
2021-07-28 09:44:13 +03:00
|
|
|
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())
|
|
|
|
|
2021-04-13 11:22:48 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|