Merged in feature/docresult (pull request #105)
Document Result Endpoint * testing * cleantesting * progress * query * lint * readme * dockerclient * api * passtest * tests * test
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package queryapitest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
queryapi "queryorchestration/pkg/queryAPI"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func CreateClientWithSync(t testing.TB, ctx context.Context, client queryapi.ClientWithResponsesInterface) *queryapi.DocClient {
|
||||
t.Helper()
|
||||
|
||||
clientCreateRes, err := client.CreateClientWithResponse(ctx, queryapi.ClientCreate{
|
||||
Name: "example_name",
|
||||
Id: "ID",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
canSync := true
|
||||
_, err = client.UpdateClientWithResponse(ctx, clientCreateRes.JSON201.Id, queryapi.ClientUpdate{
|
||||
CanSync: &canSync,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
clientRes, err := client.GetClientWithResponse(ctx, clientCreateRes.JSON201.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
return clientRes.JSON200
|
||||
}
|
||||
|
||||
func WaitForClientStatus(t testing.TB, ctx context.Context, service queryapi.ClientWithResponsesInterface, id string, status queryapi.ClientStatus) {
|
||||
t.Helper()
|
||||
|
||||
timeout := time.After(30 * time.Second)
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-timeout:
|
||||
require.NoError(t, fmt.Errorf("Timeout waiting for client status to become %s", status))
|
||||
case <-ticker.C:
|
||||
jRes, err := service.GetStatusByClientIdWithResponse(ctx, id)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
if jRes.JSON200.Status == status {
|
||||
assert.Equal(t, status, jRes.JSON200.Status)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user