2018-06-27 15:04:09 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/briandowns/spinner"
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
2018-07-06 08:06:27 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/util/fake"
|
|
|
|
"github.com/hasura/graphql-engine/cli/version"
|
2018-06-29 13:02:33 +03:00
|
|
|
"github.com/sirupsen/logrus/hooks/test"
|
2018-06-27 15:04:09 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConsoleCmd(t *testing.T) {
|
2018-06-29 13:02:33 +03:00
|
|
|
logger, _ := test.NewNullLogger()
|
2019-01-28 16:55:28 +03:00
|
|
|
ec := cli.NewExecutionContext()
|
|
|
|
ec.Telemetry.Command = "TEST"
|
|
|
|
ec.Logger = logger
|
|
|
|
ec.Spinner = spinner.New(spinner.CharSets[7], 100*time.Millisecond)
|
2019-02-14 12:37:47 +03:00
|
|
|
ec.ServerConfig = &cli.ServerConfig{
|
|
|
|
Endpoint: "http://localhost:8080",
|
|
|
|
AdminSecret: "",
|
2019-01-28 16:55:28 +03:00
|
|
|
}
|
2019-03-20 08:10:06 +03:00
|
|
|
ec.MetadataFile = []string{"metadata.yaml"}
|
2019-02-14 12:37:47 +03:00
|
|
|
|
2019-01-28 16:55:28 +03:00
|
|
|
ec.Version = version.New()
|
2019-02-14 12:37:47 +03:00
|
|
|
v, err := version.FetchServerVersion(ec.ServerConfig.Endpoint)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("getting server version failed: %v", err)
|
|
|
|
}
|
|
|
|
ec.Version.SetServerVersion(v)
|
|
|
|
err = ec.Prepare()
|
2019-01-28 16:55:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("prepare failed: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-06-27 15:04:09 +03:00
|
|
|
opts := &consoleOptions{
|
2019-01-28 16:55:28 +03:00
|
|
|
EC: ec,
|
2018-06-27 15:04:09 +03:00
|
|
|
APIPort: "9693",
|
|
|
|
ConsolePort: "9695",
|
|
|
|
Address: "localhost",
|
|
|
|
DontOpenBrowser: true,
|
|
|
|
}
|
2018-07-06 08:06:27 +03:00
|
|
|
opts.EC.Spinner.Writer = &fake.FakeWriter{}
|
2019-02-14 12:37:47 +03:00
|
|
|
err = opts.EC.ServerConfig.ParseEndpoint()
|
2018-07-09 16:47:38 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-06-27 15:04:09 +03:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
t.Log("waiting for console to start")
|
|
|
|
for opts.WG == nil {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
opts.WG.Done()
|
|
|
|
opts.WG.Done()
|
|
|
|
}()
|
2018-07-09 16:47:38 +03:00
|
|
|
err = opts.run()
|
2018-06-27 15:04:09 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed running console: %v", err)
|
|
|
|
}
|
|
|
|
// TODO: (shahidhk) curl the console endpoint for 200 response
|
|
|
|
}
|