Files
query-orchestration/test/process_test.go
T
Michael McGuinness 6648cdf1cb Merged in feature/clientexternalid (pull request #99)
Client External ID

* normalizeexternalid

* cleanopenapi

* cleanopenapi

* changingpublic

* noprecommit

* testing

* precommit

* processtest

* nodb

* tests

* tests
2025-03-11 16:31:06 +00:00

188 lines
4.3 KiB
Go

package endtoend_test
import (
"context"
"fmt"
"strings"
"testing"
"time"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/test"
queryservicetest "queryorchestration/internal/test/queryService"
queryservice "queryorchestration/pkg/queryService"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type ProcessConfig struct {
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestProcess(t *testing.T) {
ctx := context.Background()
cfg := &ProcessConfig{}
test.SetCfgProviderWithBasePath(t, cfg, "..")
net, clean := test.CreateFullNetwork(t, ctx, cfg)
defer clean()
client := queryservicetest.CreateClientWithSync(t, ctx, net.Client)
contextQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.CONTEXTFULL,
})
require.NoError(t, err)
jcfg := `{"path":"keyone"}`
jsonQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.JSONEXTRACTOR,
Config: &jcfg,
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
})
require.NoError(t, err)
newActiveVersion := int32(1)
_, err = net.Client.SetCollectorByClientIdWithResponse(ctx, client.Id, queryservice.CollectorSet{
ActiveVersion: &newActiveVersion,
Fields: &[]queryservice.CollectorField{
{
Name: "JSON_QUERY",
QueryId: jsonQueryRes.JSON201.Id,
},
},
})
require.NoError(t, err)
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
body := strings.NewReader(pdfHelloWorld)
location := test.PutObject(t, ctx, cfg, client.Uid, net.Dependencies.BucketName, "object_name", body)
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.NOTSYNCED)
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
docs, err := net.Client.ListDocumentsByClientIdWithResponse(ctx, client.Id)
assert.NoError(t, err)
assert.Len(t, *docs.JSON200, 1)
doc := (*docs.JSON200)[0]
assert.Equal(t, net.Dependencies.BucketName, doc.Bucket)
assert.Equal(t, location, doc.Key)
testRes, err := net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryTestRequest{
QueryVersion: 1,
DocumentId: doc.Id,
})
assert.NoError(t, err)
assert.Equal(t, "valueone", testRes.JSON200.Value)
aV := int32(2)
jcfg = `{"path":"keytwo"}`
res, err := net.Client.UpdateQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryUpdate{
ActiveVersion: &aV,
Config: &jcfg,
})
assert.NoError(t, err)
assert.NotNil(t, res)
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.NOTSYNCED)
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
testRes, err = net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryTestRequest{
QueryVersion: 2,
DocumentId: doc.Id,
})
assert.NoError(t, err)
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
}
func WaitForClientStatus(t testing.TB, ctx context.Context, service *queryservice.ClientWithResponses, id string, status queryservice.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
}
}
}
}
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`