81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
|
|
package queryapitest_test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
queryapitest "queryorchestration/internal/test/queryAPI"
|
||
|
|
queryapimock "queryorchestration/mocks/queryapi"
|
||
|
|
queryapi "queryorchestration/pkg/queryAPI"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/mock"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCreateClientWithSync(t *testing.T) {
|
||
|
|
ctx := context.Background()
|
||
|
|
|
||
|
|
svcClient := queryapimock.NewMockClientWithResponsesInterface(t)
|
||
|
|
|
||
|
|
svcClient.EXPECT().CreateClientWithResponse(
|
||
|
|
mock.Anything,
|
||
|
|
mock.MatchedBy(func(create queryapi.ClientCreate) bool {
|
||
|
|
return create.Name == "example_name" && create.Id == "ID"
|
||
|
|
}),
|
||
|
|
mock.Anything,
|
||
|
|
).Return(&queryapi.CreateClientResponse{
|
||
|
|
JSON201: &queryapi.ClientIDBody{
|
||
|
|
Id: "ID",
|
||
|
|
},
|
||
|
|
}, nil)
|
||
|
|
|
||
|
|
svcClient.EXPECT().UpdateClientWithResponse(
|
||
|
|
mock.Anything,
|
||
|
|
mock.MatchedBy(func(id string) bool {
|
||
|
|
return id == "ID"
|
||
|
|
}),
|
||
|
|
mock.MatchedBy(func(create queryapi.ClientUpdate) bool {
|
||
|
|
return *create.CanSync == true
|
||
|
|
}),
|
||
|
|
mock.Anything,
|
||
|
|
).Return(&queryapi.UpdateClientResponse{}, nil)
|
||
|
|
|
||
|
|
svcClient.EXPECT().GetClientWithResponse(
|
||
|
|
mock.Anything,
|
||
|
|
mock.MatchedBy(func(id string) bool {
|
||
|
|
return id == "ID"
|
||
|
|
}),
|
||
|
|
mock.Anything,
|
||
|
|
).Return(&queryapi.GetClientResponse{
|
||
|
|
JSON200: &queryapi.DocClient{
|
||
|
|
Id: "ID",
|
||
|
|
},
|
||
|
|
}, nil)
|
||
|
|
|
||
|
|
client := queryapitest.CreateClientWithSync(t, ctx, svcClient)
|
||
|
|
|
||
|
|
assert.NotNil(t, client)
|
||
|
|
assert.NotNil(t, client)
|
||
|
|
assert.EqualExportedValues(t, queryapi.DocClient{
|
||
|
|
Id: "ID",
|
||
|
|
}, *client)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestWaitForClientStatus(t *testing.T) {
|
||
|
|
ctx := context.Background()
|
||
|
|
client := queryapimock.NewMockClientWithResponsesInterface(t)
|
||
|
|
|
||
|
|
client.EXPECT().GetStatusByClientIdWithResponse(
|
||
|
|
mock.Anything,
|
||
|
|
mock.MatchedBy(func(id string) bool {
|
||
|
|
return id == "id"
|
||
|
|
}),
|
||
|
|
).Return(&queryapi.GetStatusByClientIdResponse{
|
||
|
|
JSON200: &queryapi.ClientStatusBody{
|
||
|
|
Status: queryapi.INSYNC,
|
||
|
|
},
|
||
|
|
}, nil)
|
||
|
|
|
||
|
|
queryapitest.WaitForClientStatus(t, ctx, client, "id", queryapi.INSYNC)
|
||
|
|
}
|