graphql-engine/cli/integration_test/v2/console.go

65 lines
1.6 KiB
Go
Raw Normal View History

package v2
import (
2021-09-07 16:33:58 +03:00
"fmt"
"net"
"net/url"
"os"
2021-09-07 16:33:58 +03:00
"sync"
"testing"
"time"
2021-09-07 16:33:58 +03:00
"github.com/avast/retry-go"
"github.com/hasura/graphql-engine/cli/v2"
"github.com/hasura/graphql-engine/cli/v2/commands"
2021-09-07 16:33:58 +03:00
"github.com/stretchr/testify/require"
)
func TestConsoleCmd(t *testing.T, ec *cli.ExecutionContext) {
apiHost := &url.URL{
Host: "localhost",
Scheme: "http",
}
opts := &commands.ConsoleOptions{
EC: ec,
APIPort: "9693",
APIHost: apiHost,
ConsolePort: "9695",
Address: "localhost",
DontOpenBrowser: true,
APIServerInterruptSignal: make(chan os.Signal),
ConsoleServerInterruptSignal: make(chan os.Signal),
}
2021-09-07 16:33:58 +03:00
var wg sync.WaitGroup
wg.Add(1)
go func() {
2021-09-07 16:33:58 +03:00
defer wg.Done()
t.Log("waiting for console to start")
2021-09-07 16:33:58 +03:00
timeout := 1 * time.Minute
require.NoError(t, retry.Do(
func() error {
_, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", opts.Address, opts.APIPort), timeout)
return err
}, retry.Attempts(5),
))
require.NoError(t, retry.Do(
func() error {
_, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", opts.Address, opts.ConsolePort), timeout)
return err
}, retry.Attempts(5),
))
opts.APIServerInterruptSignal <- os.Interrupt
opts.ConsoleServerInterruptSignal <- os.Interrupt
close(opts.APIServerInterruptSignal)
close(opts.ConsoleServerInterruptSignal)
}()
err := opts.Run()
if err != nil {
t.Fatalf("failed running console: %v", err)
}
2021-09-07 16:33:58 +03:00
wg.Wait()
// TODO: (shahidhk) curl the console endpoint for 200 response
}