2021-02-17 07:20:19 +03:00
|
|
|
package statestore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/hasura"
|
2021-02-17 07:20:19 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/hasura/catalogstate"
|
2021-02-17 07:20:19 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
2021-02-17 07:20:19 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-10-28 10:50:27 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-02-17 07:20:19 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientCatalogState_GetCLIState(t *testing.T) {
|
2021-06-03 16:26:28 +03:00
|
|
|
port, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
2021-02-17 07:20:19 +03:00
|
|
|
defer teardown()
|
|
|
|
type fields struct {
|
|
|
|
Client *httpc.Client
|
|
|
|
path string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
2022-10-28 10:50:27 +03:00
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want CLIState
|
|
|
|
wantErr bool
|
|
|
|
assertErr require.ErrorAssertionFunc
|
2021-02-17 07:20:19 +03:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"can get catalog state",
|
|
|
|
fields{
|
|
|
|
Client: testutil.NewHttpcClient(t, port, nil),
|
|
|
|
path: "v1/metadata",
|
|
|
|
},
|
|
|
|
CLIState{
|
|
|
|
Migrations: MigrationsState{
|
|
|
|
"test": {
|
|
|
|
"123": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
2022-10-28 10:50:27 +03:00
|
|
|
require.NoError,
|
2021-02-17 07:20:19 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := NewCLICatalogState(catalogstate.New(tt.fields.Client, tt.fields.path))
|
|
|
|
_, err := c.Set(CLIState{
|
|
|
|
Migrations: MigrationsState{
|
|
|
|
"test": {
|
|
|
|
"123": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
got, err := c.Get()
|
2022-10-28 10:50:27 +03:00
|
|
|
tt.assertErr(t, err)
|
2021-02-17 07:20:19 +03:00
|
|
|
if tt.wantErr {
|
2022-10-28 10:50:27 +03:00
|
|
|
return
|
2021-02-17 07:20:19 +03:00
|
|
|
}
|
2022-10-28 10:50:27 +03:00
|
|
|
assert.Equal(t, tt.want, *got)
|
2021-02-17 07:20:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCLICatalogState_Set(t *testing.T) {
|
2021-06-03 16:26:28 +03:00
|
|
|
port, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
2021-02-17 07:20:19 +03:00
|
|
|
defer teardown()
|
|
|
|
type fields struct {
|
|
|
|
client hasura.CatalogStateOperations
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
state CLIState
|
|
|
|
}
|
|
|
|
tests := []struct {
|
2022-10-28 10:50:27 +03:00
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want string
|
|
|
|
wantErr bool
|
|
|
|
assertErr require.ErrorAssertionFunc
|
2021-02-17 07:20:19 +03:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"can set CLI state",
|
|
|
|
fields{
|
|
|
|
client: catalogstate.New(testutil.NewHttpcClient(t, port, nil), "v1/metadata"),
|
|
|
|
},
|
|
|
|
args{
|
|
|
|
state: CLIState{
|
|
|
|
Migrations: MigrationsState{
|
|
|
|
"test": map[string]bool{
|
|
|
|
"123": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Settings: nil,
|
|
|
|
},
|
|
|
|
},
|
2021-03-08 14:59:35 +03:00
|
|
|
`{
|
|
|
|
"message": "success"
|
|
|
|
}`,
|
2021-02-17 07:20:19 +03:00
|
|
|
false,
|
2022-10-28 10:50:27 +03:00
|
|
|
require.NoError,
|
2021-02-17 07:20:19 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &CLICatalogState{
|
|
|
|
client: tt.fields.client,
|
|
|
|
}
|
|
|
|
got, err := c.Set(tt.args.state)
|
2022-10-28 10:50:27 +03:00
|
|
|
tt.assertErr(t, err)
|
2021-02-17 07:20:19 +03:00
|
|
|
if tt.wantErr {
|
2022-10-28 10:50:27 +03:00
|
|
|
return
|
2021-02-17 07:20:19 +03:00
|
|
|
}
|
2022-10-28 10:50:27 +03:00
|
|
|
b, err := ioutil.ReadAll(got)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.want, string(b))
|
2021-02-17 07:20:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|