2020-02-24 19:14:46 +03:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"github.com/hasura/graphql-engine/cli/commands"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInitCmd(t *testing.T, ec *cli.ExecutionContext, initDir string) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
opts *commands.InitOptions
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{"only-init-dir", &commands.InitOptions{
|
|
|
|
EC: ec,
|
2020-03-26 06:24:05 +03:00
|
|
|
Version: cli.V2,
|
2020-02-24 19:14:46 +03:00
|
|
|
Endpoint: os.Getenv("HASURA_GRAPHQL_TEST_ENDPOINT"),
|
|
|
|
AdminSecret: os.Getenv("HASURA_GRAPHQL_TEST_ADMIN_SECRET"),
|
|
|
|
InitDir: filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000))),
|
|
|
|
}, nil},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
err := tc.opts.Run()
|
|
|
|
if err != tc.err {
|
|
|
|
t.Fatalf("%s: expected %v, got %v", tc.name, tc.err, err)
|
|
|
|
}
|
|
|
|
// TODO: (shahidhk) need to verify the contents of the spec generated
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|