Files
query-orchestration/test/process_test.go
T
Michael McGuinness fee71e7740 Merged in feature/postprocessing (pull request #114)
Feature/postprocessing

* tests

* passtest

* fixshorttests

* mosttests

* improvingbasedockerfile

* testspeeds

* testing

* host

* canparallel

* clean

* passfullsuite

* singlepagemax

* test

* findfeatures

* findstables

* tbls

* tablestoo

* tablestoo

* lateraltests

* tableloc

* cleanup

* inlinetable

* childids

* cleanup

* tests
2025-04-22 14:40:16 +00:00

231 lines
5.4 KiB
Go

package endtoend_test
import (
"context"
"net/http"
"strings"
"testing"
"time"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/aws"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/test"
queryapitest "queryorchestration/internal/test/queryAPI"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/google/uuid"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type Config struct {
serviceconfig.BaseConfig
aws.AWSConfig
objectstore.ObjectStoreConfig
}
func TestProcess(t *testing.T) {
ctx := context.Background()
cfg := &Config{}
test.SetCfgProvider(t, cfg)
net, clean := test.CreateFullNetwork(t, ctx, cfg)
defer clean()
client := queryapitest.CreateClientWithSync(t, ctx, net.Client)
contextQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
})
require.NoError(t, err)
require.Equal(t, http.StatusCreated, contextQueryRes.StatusCode())
jcfg := `{"path":"keyone"}`
jsonQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.JSONEXTRACTOR,
Config: &jcfg,
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
})
require.NoError(t, err)
require.Equal(t, http.StatusCreated, jsonQueryRes.StatusCode())
newActiveVersion := int32(1)
collRes, err := net.Client.SetCollectorByClientIdWithResponse(ctx, client.Id, queryapi.CollectorSet{
ActiveVersion: &newActiveVersion,
Fields: &[]queryapi.CollectorField{
{
Name: "JSON_QUERY",
QueryId: jsonQueryRes.JSON201.Id,
},
},
})
require.NoError(t, err)
require.Equal(t, http.StatusOK, collRes.StatusCode())
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
textractBody := "Hello World"
textractExpectation := test.CreateDetectDocumentTextExpectation(
t,
net.Dependencies.MockServer,
textractBody,
)
part := uint16(0)
importKey := objectstore.BucketKey{
ClientID: client.Id,
EntityID: uuid.New(),
Location: objectstore.Import,
CreatedAt: time.Now().UTC(),
Part: &part,
}
inputFile := strings.NewReader(pdfHelloWorld)
test.PutObject(t, ctx, cfg, test.PutObjectParams{
Bucket: net.Dependencies.BucketName,
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,
EntityID: uuid.New(),
Location: objectstore.Text,
CreatedAt: time.Now().UTC(),
Part: &part,
}
inputFile = strings.NewReader(textractBody)
test.PutObject(t, ctx, cfg, test.PutObjectParams{
Bucket: net.Dependencies.BucketName,
File: inputFile,
Key: textKey,
})
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
docs, err := net.Client.ListDocumentsByClientIdWithResponse(ctx, client.Id)
require.NoError(t, err)
assert.Len(t, *docs.JSON200, 1)
doc := (*docs.JSON200)[0]
expectedDoc := queryapi.Document{
Id: doc.Id,
Hash: doc.Hash,
ClientId: client.Id,
Fields: map[string]any{
"JSON_QUERY": "valueone",
},
}
docRes, err := net.Client.GetDocumentWithResponse(ctx, doc.Id)
require.NoError(t, err)
require.NotNil(t, docRes)
require.NotNil(t, docRes.JSON200)
fullDoc := *docRes.JSON200
assert.EqualExportedValues(t, expectedDoc, fullDoc)
jcfg = `{"path":"keytwo"}`
av := int32(2)
_, err = net.Client.UpdateQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryapi.QueryUpdate{
ActiveVersion: &av,
Config: &jcfg,
})
require.NoError(t, err)
expectedDoc.Fields = map[string]any{
"JSON_QUERY": "valuetwo",
}
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.NOTSYNCED)
queryapitest.WaitForClientStatus(t, ctx, net.Client, client.Id, queryapi.INSYNC)
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)
testRes, err := net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryapi.QueryTestRequest{
QueryVersion: 1,
DocumentId: doc.Id,
})
require.NoError(t, err)
assert.Equal(t, "valueone", testRes.JSON200.Value)
testRes, err = net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, 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
%
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/Version /1.4
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/MediaBox [0 0 612 792]
/Resources <<
/Font <<
/F1 <<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>>
>>
>>
/Contents 4 0 R
>>
endobj
4 0 obj
<<
/Length
44
>>
stream
BT
/F1 24 Tf
100 700 Td
(Hello World!) Tj
ET
endstream
endobj
xref
0 5
0000000000 65535 f
0000000015 00000 n
0000000086 00000 n
0000000151 00000 n
0000000376 00000 n
trailer
<<
/Size 5
/Root 1 0 R
>>
startxref
472
%%EOF`