2021-04-13 11:22:48 +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-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 codegen", func() {
|
2021-04-13 11:22:48 +03:00
|
|
|
|
|
|
|
var dirName string
|
|
|
|
var teardown func()
|
|
|
|
BeforeEach(func() {
|
|
|
|
dirName = 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{
|
|
|
|
Args: []string{"init", dirName},
|
|
|
|
})
|
|
|
|
editEndpointInConfig(filepath.Join(dirName, defaultConfigFilename), hgeEndpoint)
|
|
|
|
|
|
|
|
teardown = func() {
|
|
|
|
os.RemoveAll(dirName)
|
|
|
|
teardownHGE()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-03 16:26:28 +03:00
|
|
|
AfterEach(func() { teardown() })
|
2021-04-13 11:22:48 +03:00
|
|
|
|
|
|
|
Context("actions codegen tests", func() {
|
2021-06-03 16:26:28 +03:00
|
|
|
It("creates the code for all actions specified framework and in directory as in config.yaml file", func() {
|
2021-04-13 11:22:48 +03:00
|
|
|
testutil.RunCommandAndSucceed(testutil.CmdOpts{
|
|
|
|
Args: []string{"actions", "use-codegen", "--framework", "nodejs-express", "--output-dir", "codegen", "--with-starter-kit", "true"},
|
|
|
|
WorkingDirectory: dirName,
|
|
|
|
})
|
2021-06-03 16:26:28 +03:00
|
|
|
session := testutil.Hasura(testutil.CmdOpts{
|
2021-04-13 11:22:48 +03:00
|
|
|
Args: []string{"actions", "codegen"},
|
|
|
|
WorkingDirectory: dirName,
|
|
|
|
})
|
2021-05-24 05:33:45 +03:00
|
|
|
Eventually(session, 60*60).Should(Exit(0))
|
2021-05-14 22:09:01 +03:00
|
|
|
Eventually(session.Wait().Err.Contents()).Should(ContainSubstring("Codegen files generated at codegen"))
|
2021-04-13 11:22:48 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|