mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
3136ffad1b
> ### Description Update `go.mod` to allow other packages to import [v2.0.0 versions](https://blog.golang.org/v2-go-modules). ### Changelog - [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ### Affected components - [x] CLI https://github.com/hasura/graphql-engine-mono/pull/1584 GitOrigin-RevId: a5d17ad20289d1cd7217763f56ef3ba6552d69c4
121 lines
2.3 KiB
Go
121 lines
2.3 KiB
Go
package statestore
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/hasura"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/hasura/catalogstate"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestClientCatalogState_GetCLIState(t *testing.T) {
|
|
port, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
|
defer teardown()
|
|
type fields struct {
|
|
Client *httpc.Client
|
|
path string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want CLIState
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"can get catalog state",
|
|
fields{
|
|
Client: testutil.NewHttpcClient(t, port, nil),
|
|
path: "v1/metadata",
|
|
},
|
|
CLIState{
|
|
Migrations: MigrationsState{
|
|
"test": {
|
|
"123": true,
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
},
|
|
}
|
|
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()
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tt.want, *got)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCLICatalogState_Set(t *testing.T) {
|
|
port, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
|
|
defer teardown()
|
|
type fields struct {
|
|
client hasura.CatalogStateOperations
|
|
}
|
|
type args struct {
|
|
state CLIState
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"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,
|
|
},
|
|
},
|
|
`{
|
|
"message": "success"
|
|
}`,
|
|
false,
|
|
},
|
|
}
|
|
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)
|
|
if tt.wantErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
b, err := ioutil.ReadAll(got)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tt.want, string(b))
|
|
}
|
|
})
|
|
}
|
|
}
|