2020-02-24 19:14:46 +03:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
2021-05-17 03:29:11 +03:00
|
|
|
"fmt"
|
2021-10-07 17:23:19 +03:00
|
|
|
"io/ioutil"
|
2020-02-24 19:14:46 +03:00
|
|
|
"os"
|
2021-10-07 17:23:19 +03:00
|
|
|
"path/filepath"
|
2020-02-24 19:14:46 +03:00
|
|
|
"testing"
|
|
|
|
|
2021-10-07 17:23:19 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-03-10 11:12:55 +03:00
|
|
|
"gopkg.in/yaml.v3"
|
2021-10-07 17:23:19 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/commands"
|
2020-02-24 19:14:46 +03:00
|
|
|
)
|
|
|
|
|
2021-10-07 17:23:19 +03:00
|
|
|
// TODO: move this to testutil
|
|
|
|
func editEndpointInConfig(t *testing.T, configFilePath, endpoint string) {
|
|
|
|
var config cli.Config
|
|
|
|
b, err := ioutil.ReadFile(configFilePath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(b, &config)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
config.Endpoint = endpoint
|
|
|
|
|
|
|
|
b, err = yaml.Marshal(&config)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(configFilePath, b, 0655)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
}
|
2021-05-17 03:29:11 +03:00
|
|
|
func TestInitCmd(t *testing.T, ec *cli.ExecutionContext, initDir, hasuraPort string) {
|
2020-02-24 19:14:46 +03:00
|
|
|
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
|
|
|
AdminSecret: os.Getenv("HASURA_GRAPHQL_TEST_ADMIN_SECRET"),
|
2020-04-22 13:24:24 +03:00
|
|
|
InitDir: initDir,
|
2020-02-24 19:14:46 +03:00
|
|
|
}, 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)
|
|
|
|
}
|
2021-10-07 17:23:19 +03:00
|
|
|
editEndpointInConfig(t, filepath.Join(initDir, "config.yaml"), fmt.Sprintf("http://localhost:%s", hasuraPort))
|
2020-02-24 19:14:46 +03:00
|
|
|
// TODO: (shahidhk) need to verify the contents of the spec generated
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|