graphql-engine/cli/commands/migrate_status_test.go
nizar-m f83a8e591f rename access-key to admin-secret (close #1347) (#1540)
Rename the admin secret key header used to access GraphQL engine from X-Hasura-Access-Key to X-Hasura-Admin-Secret.

Server CLI and console all support the older flag but marks it as deprecated.
2019-02-14 15:07:47 +05:30

71 lines
1.8 KiB
Go

package commands
import (
"math/rand"
"net/url"
"os"
"path/filepath"
"strconv"
"testing"
"time"
"github.com/briandowns/spinner"
"github.com/hasura/graphql-engine/cli"
"github.com/hasura/graphql-engine/cli/migrate"
"github.com/hasura/graphql-engine/cli/version"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
)
func testMigrateStatus(t *testing.T, endpoint *url.URL, migrationsDir string, expectedStatus *migrate.Status) {
logger, _ := test.NewNullLogger()
opts := &migrateStatusOptions{
EC: &cli.ExecutionContext{
Logger: logger,
Spinner: spinner.New(spinner.CharSets[7], 100*time.Millisecond),
MigrationDir: migrationsDir,
ServerConfig: &cli.ServerConfig{
Endpoint: endpoint.String(),
AdminSecret: os.Getenv("HASURA_GRAPHQL_TEST_ADMIN_SECRET"),
ParsedEndpoint: endpoint,
},
},
}
opts.EC.Version = version.New()
v, err := version.FetchServerVersion(opts.EC.ServerConfig.Endpoint)
if err != nil {
t.Fatalf("getting server version failed: %v", err)
}
opts.EC.Version.SetServerVersion(v)
status, err := opts.run()
if err != nil {
t.Fatalf("failed fetching migration status: %v", err)
}
assert.Equal(t, expectedStatus, status)
}
func TestMigrateStatusWithInvalidEndpoint(t *testing.T) {
logger, _ := test.NewNullLogger()
opts := &migrateStatusOptions{
EC: &cli.ExecutionContext{
Logger: logger,
Spinner: spinner.New(spinner.CharSets[7], 100*time.Millisecond),
MigrationDir: filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000))),
ServerConfig: &cli.ServerConfig{
Endpoint: ":",
AdminSecret: "",
ParsedEndpoint: &url.URL{},
},
},
}
opts.EC.Version = version.New()
opts.EC.Version.SetServerVersion("")
_, err := opts.run()
if err == nil {
t.Fatalf("expected err not to be nil")
}
}