Merged in feature/mockserver (pull request #135)
Single Mock Server * mockserver * mockserver * reqs * mockserver * slowrunner * someoptimisedqueries * passedfullsuite * passedfullsuite
This commit is contained in:
+42
-36
@@ -1,8 +1,8 @@
|
||||
package endtoend_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -25,58 +25,69 @@ type Config struct {
|
||||
}
|
||||
|
||||
func TestProcess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &Config{}
|
||||
|
||||
net, clean := test.CreateFullNetwork(t, ctx, cfg)
|
||||
net, clean := test.CreateFullNetwork(t, t.Context(), cfg)
|
||||
defer clean()
|
||||
|
||||
client := queryapitest.CreateClientWithSync(t, ctx, net.Client)
|
||||
_, jsonId := queryapitest.CreateDependentQueries(t, net.Client, client.Id)
|
||||
|
||||
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var clientId queryapi.ClientID
|
||||
var jsonId queryapi.QueryID
|
||||
var textractExpectation test.MockExpectation
|
||||
textractBody := "Hello World"
|
||||
textractExpectation := test.CreateDetectDocumentTextExpectation(
|
||||
t,
|
||||
net.Dependencies.MockServer,
|
||||
textractBody,
|
||||
)
|
||||
wg.Add(3)
|
||||
go func(t testing.TB) {
|
||||
_, jsonId = queryapitest.CreateDependentQueries(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
clientId = queryapitest.CreateClientWithSync(t, net.Client)
|
||||
wg.Done()
|
||||
}(t)
|
||||
go func(t testing.TB) {
|
||||
textractExpectation = test.CreateDetectDocumentTextExpectation(
|
||||
t,
|
||||
net.Dependencies.MockServer,
|
||||
textractBody,
|
||||
)
|
||||
wg.Done()
|
||||
}(t)
|
||||
|
||||
wg.Wait()
|
||||
|
||||
queryapitest.SetQueryForClient(t, net.Client, clientId, jsonId)
|
||||
|
||||
part := uint16(0)
|
||||
importKey := objectstore.BucketKey{
|
||||
ClientID: client.Id,
|
||||
ClientID: clientId,
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
Part: &part,
|
||||
}
|
||||
inputFile := strings.NewReader(pdfHelloWorld)
|
||||
test.PutObject(t, ctx, cfg, test.PutObjectParams{
|
||||
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||
File: inputFile,
|
||||
Key: importKey,
|
||||
})
|
||||
|
||||
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.NOTSYNCED)
|
||||
|
||||
test.WaitForMockEndpoint(t, net.Dependencies.MockServer, textractExpectation.Request)
|
||||
textKey := objectstore.BucketKey{
|
||||
ClientID: client.Id,
|
||||
ClientID: clientId,
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Text,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
Part: &part,
|
||||
}
|
||||
inputFile = strings.NewReader(textractBody)
|
||||
test.PutObject(t, ctx, cfg, test.PutObjectParams{
|
||||
test.PutObject(t, t.Context(), cfg, test.PutObjectParams{
|
||||
File: inputFile,
|
||||
Key: textKey,
|
||||
})
|
||||
|
||||
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
|
||||
docs, err := net.Client.ListDocumentsByClientIdWithResponse(ctx, client.Id)
|
||||
docs, err := net.Client.ListDocumentsByClientIdWithResponse(t.Context(), clientId)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, *docs.JSON200, 1)
|
||||
doc := (*docs.JSON200)[0]
|
||||
@@ -84,13 +95,13 @@ func TestProcess(t *testing.T) {
|
||||
expectedDoc := queryapi.Document{
|
||||
Id: doc.Id,
|
||||
Hash: doc.Hash,
|
||||
ClientId: client.Id,
|
||||
ClientId: clientId,
|
||||
Fields: map[string]any{
|
||||
"JSON_QUERY": "valueone",
|
||||
},
|
||||
}
|
||||
|
||||
docRes, err := net.Client.GetDocumentWithResponse(ctx, doc.Id)
|
||||
docRes, err := net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, docRes)
|
||||
require.NotNil(t, docRes.JSON200)
|
||||
@@ -99,7 +110,7 @@ func TestProcess(t *testing.T) {
|
||||
|
||||
jcfg := `{"path":"keytwo"}`
|
||||
av := int32(2)
|
||||
_, err = net.Client.UpdateQueryWithResponse(ctx, jsonId, queryapi.QueryUpdate{
|
||||
_, err = net.Client.UpdateQueryWithResponse(t.Context(), jsonId, queryapi.QueryUpdate{
|
||||
ActiveVersion: &av,
|
||||
Config: &jcfg,
|
||||
})
|
||||
@@ -108,33 +119,28 @@ func TestProcess(t *testing.T) {
|
||||
"JSON_QUERY": "valuetwo",
|
||||
}
|
||||
|
||||
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.NOTSYNCED)
|
||||
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.NOTSYNCED)
|
||||
queryapitest.WaitForClientStatus(t, t.Context(), net.Client, clientId, queryapi.INSYNC)
|
||||
|
||||
docRes, err = net.Client.GetDocumentWithResponse(ctx, doc.Id)
|
||||
docRes, err = net.Client.GetDocumentWithResponse(t.Context(), doc.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, docRes)
|
||||
require.NotNil(t, docRes.JSON200)
|
||||
assert.EqualExportedValues(t, expectedDoc, *docRes.JSON200)
|
||||
|
||||
testRes, err := net.Client.TestQueryWithResponse(ctx, jsonId, queryapi.QueryTestRequest{
|
||||
testRes, err := net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 1,
|
||||
DocumentId: doc.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "valueone", testRes.JSON200.Value)
|
||||
testRes, err = net.Client.TestQueryWithResponse(ctx, jsonId, queryapi.QueryTestRequest{
|
||||
|
||||
testRes, err = net.Client.TestQueryWithResponse(t.Context(), jsonId, queryapi.QueryTestRequest{
|
||||
QueryVersion: 2,
|
||||
DocumentId: doc.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
|
||||
|
||||
docRes, err = net.Client.GetDocumentWithResponse(ctx, doc.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, docRes)
|
||||
require.NotNil(t, docRes.JSON200)
|
||||
assert.EqualExportedValues(t, expectedDoc, *docRes.JSON200)
|
||||
}
|
||||
|
||||
const pdfHelloWorld = `%PDF-1.4
|
||||
|
||||
Reference in New Issue
Block a user