2025-02-12 19:00:25 +00:00
|
|
|
package endtoend_test
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-02-06 15:00:26 +00:00
|
|
|
"fmt"
|
2025-03-05 12:05:46 +00:00
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-02-05 12:52:41 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
2025-02-03 17:30:50 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-03-11 16:31:06 +00:00
|
|
|
queryservicetest "queryorchestration/internal/test/queryService"
|
2025-02-03 17:30:50 +00:00
|
|
|
queryservice "queryorchestration/pkg/queryService"
|
|
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
"github.com/oapi-codegen/runtime/types"
|
2025-02-03 17:30:50 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-02-03 17:30:50 +00:00
|
|
|
)
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
type ProcessConfig struct {
|
|
|
|
|
serviceconfig.BaseConfig
|
2025-02-05 12:52:41 +00:00
|
|
|
objectstore.ObjectStoreConfig
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
func TestProcess(t *testing.T) {
|
2025-02-03 17:30:50 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
cfg := &ProcessConfig{}
|
2025-03-11 16:31:06 +00:00
|
|
|
test.SetCfgProviderWithBasePath(t, cfg, "..")
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
net, clean := test.CreateFullNetwork(t, ctx, cfg)
|
2025-02-05 12:52:41 +00:00
|
|
|
defer clean()
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
client := queryservicetest.CreateClientWithSync(t, ctx, net.Client)
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
contextQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
|
2025-02-11 15:22:59 +00:00
|
|
|
Type: queryservice.CONTEXTFULL,
|
|
|
|
|
})
|
2025-03-11 16:31:06 +00:00
|
|
|
require.NoError(t, err)
|
2025-02-21 17:05:37 +00:00
|
|
|
jcfg := `{"path":"keyone"}`
|
2025-03-11 16:31:06 +00:00
|
|
|
jsonQueryRes, err := net.Client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
|
2025-02-11 15:22:59 +00:00
|
|
|
Type: queryservice.JSONEXTRACTOR,
|
2025-02-13 00:23:13 +00:00
|
|
|
Config: &jcfg,
|
2025-02-11 15:22:59 +00:00
|
|
|
RequiredQueries: &[]types.UUID{contextQueryRes.JSON201.Id},
|
|
|
|
|
})
|
2025-03-11 16:31:06 +00:00
|
|
|
require.NoError(t, err)
|
2025-03-10 13:00:57 +00:00
|
|
|
newActiveVersion := int32(1)
|
2025-03-11 16:31:06 +00:00
|
|
|
_, err = net.Client.SetCollectorByClientIdWithResponse(ctx, client.Id, queryservice.CollectorSet{
|
2025-02-11 15:22:59 +00:00
|
|
|
ActiveVersion: &newActiveVersion,
|
2025-03-10 11:03:00 +00:00
|
|
|
Fields: &[]queryservice.CollectorField{
|
2025-02-11 15:22:59 +00:00
|
|
|
{
|
|
|
|
|
Name: "JSON_QUERY",
|
|
|
|
|
QueryId: jsonQueryRes.JSON201.Id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-03-11 16:31:06 +00:00
|
|
|
require.NoError(t, err)
|
2025-02-11 15:22:59 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
|
2025-02-21 17:05:37 +00:00
|
|
|
|
2025-02-28 13:11:53 +00:00
|
|
|
body := strings.NewReader(pdfHelloWorld)
|
2025-03-11 16:31:06 +00:00
|
|
|
location := test.PutObject(t, ctx, cfg, client.Uid, net.Dependencies.BucketName, "object_name", body)
|
2025-02-21 17:05:37 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.NOTSYNCED)
|
|
|
|
|
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
|
2025-02-21 17:05:37 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
docs, err := net.Client.ListDocumentsByClientIdWithResponse(ctx, client.Id)
|
2025-02-21 17:05:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Len(t, *docs.JSON200, 1)
|
|
|
|
|
doc := (*docs.JSON200)[0]
|
2025-03-11 16:31:06 +00:00
|
|
|
assert.Equal(t, net.Dependencies.BucketName, doc.Bucket)
|
2025-02-21 17:05:37 +00:00
|
|
|
assert.Equal(t, location, doc.Key)
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
testRes, err := net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryTestRequest{
|
2025-02-21 17:05:37 +00:00
|
|
|
QueryVersion: 1,
|
|
|
|
|
DocumentId: doc.Id,
|
|
|
|
|
})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "valueone", testRes.JSON200.Value)
|
|
|
|
|
|
|
|
|
|
aV := int32(2)
|
|
|
|
|
jcfg = `{"path":"keytwo"}`
|
2025-03-11 16:31:06 +00:00
|
|
|
res, err := net.Client.UpdateQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryUpdate{
|
2025-02-21 17:05:37 +00:00
|
|
|
ActiveVersion: &aV,
|
|
|
|
|
Config: &jcfg,
|
|
|
|
|
})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, res)
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.NOTSYNCED)
|
|
|
|
|
WaitForClientStatus(t, ctx, net.Client, client.Id, queryservice.INSYNC)
|
2025-02-21 17:05:37 +00:00
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
testRes, err = net.Client.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryTestRequest{
|
2025-02-21 17:05:37 +00:00
|
|
|
QueryVersion: 2,
|
|
|
|
|
DocumentId: doc.Id,
|
|
|
|
|
})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 16:31:06 +00:00
|
|
|
func WaitForClientStatus(t testing.TB, ctx context.Context, service *queryservice.ClientWithResponses, id string, status queryservice.ClientStatus) {
|
2025-02-28 13:11:53 +00:00
|
|
|
t.Helper()
|
|
|
|
|
|
2025-02-21 17:05:37 +00:00
|
|
|
timeout := time.After(30 * time.Second)
|
|
|
|
|
ticker := time.NewTicker(500 * time.Millisecond)
|
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-timeout:
|
2025-03-10 11:03:00 +00:00
|
|
|
require.NoError(t, fmt.Errorf("Timeout waiting for client status to become %s", status))
|
2025-02-21 17:05:37 +00:00
|
|
|
case <-ticker.C:
|
2025-03-10 11:03:00 +00:00
|
|
|
jRes, err := service.GetStatusByClientIdWithResponse(ctx, id)
|
2025-02-21 17:05:37 +00:00
|
|
|
if err != nil {
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if jRes.JSON200.Status == status {
|
|
|
|
|
assert.Equal(t, status, jRes.JSON200.Status)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-03 17:30:50 +00:00
|
|
|
}
|
2025-02-28 13:11:53 +00:00
|
|
|
|
|
|
|
|
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`
|