Merged in feature/e2etest (pull request #74)

Feature/e2etest

* e2etest

* testcleanups
This commit is contained in:
Michael McGuinness
2025-02-21 17:05:37 +00:00
parent 3d434eedb8
commit 08d2296717
16 changed files with 654 additions and 79 deletions
+66 -2
View File
@@ -12,6 +12,7 @@ import (
queryservice "queryorchestration/pkg/queryService"
"strings"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/service/s3"
awstypes "github.com/aws/aws-sdk-go-v2/service/s3/types"
@@ -172,7 +173,7 @@ func TestProcess(t *testing.T) {
Type: queryservice.CONTEXTFULL,
})
assert.NoError(t, err)
jcfg := `{"path":"id"}`
jcfg := `{"path":"keyone"}`
jsonQueryRes, err := qService.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.JSONEXTRACTOR,
Config: &jcfg,
@@ -191,12 +192,75 @@ func TestProcess(t *testing.T) {
})
assert.NoError(t, err)
jRes, err := qService.GetJobWithResponse(ctx, jobRes.JSON201.Id)
assert.NoError(t, err)
assert.Equal(t, queryservice.INSYNC, jRes.JSON200.Status)
location := fmt.Sprintf("%s/%s/%s", clientRes.JSON201.Id, jobRes.JSON201.Id, "object_name")
body := strings.NewReader("hello world")
body := strings.NewReader(`{"keyone":"valueone","keytwo":"valuetwo"}`)
_, err = cfg.StoreClient.PutObject(ctx, &s3.PutObjectInput{
Bucket: &bucketName,
Key: &location,
Body: body,
})
assert.NoError(t, err)
WaitForJobStatus(t, ctx, qService, jobRes.JSON201.Id, queryservice.NOTSYNCED)
WaitForJobStatus(t, ctx, qService, jobRes.JSON201.Id, queryservice.INSYNC)
docs, err := qService.ListDocumentsByJobIdWithResponse(ctx, jobRes.JSON201.Id)
assert.NoError(t, err)
assert.Len(t, *docs.JSON200, 1)
doc := (*docs.JSON200)[0]
assert.Equal(t, bucketName, doc.Bucket)
assert.Equal(t, location, doc.Key)
testRes, err := qService.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 := qService.UpdateQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryUpdate{
ActiveVersion: &aV,
Config: &jcfg,
})
assert.NoError(t, err)
assert.NotNil(t, res)
WaitForJobStatus(t, ctx, qService, jobRes.JSON201.Id, queryservice.NOTSYNCED)
WaitForJobStatus(t, ctx, qService, jobRes.JSON201.Id, queryservice.INSYNC)
testRes, err = qService.TestQueryWithResponse(ctx, jsonQueryRes.JSON201.Id, queryservice.QueryTestRequest{
QueryVersion: 2,
DocumentId: doc.Id,
})
assert.NoError(t, err)
assert.Equal(t, "valuetwo", testRes.JSON200.Value)
}
func WaitForJobStatus(t testing.TB, ctx context.Context, service *queryservice.ClientWithResponses, id types.UUID, status queryservice.JobStatus) {
timeout := time.After(30 * time.Second)
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-timeout:
t.Fatalf("Timeout waiting for job status to become %s", status)
case <-ticker.C:
jRes, err := service.GetJobWithResponse(ctx, id)
if err != nil {
assert.NoError(t, err)
}
if jRes.JSON200.Status == status {
assert.Equal(t, status, jRes.JSON200.Status)
return
}
}
}
}
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestQueryServiceOpenAPI(t *testing.T) {
func TestQueryServiceAccessories(t *testing.T) {
ctx := context.Background()
c, cleanup := test.CreateServiceNetwork(t, ctx, &test.ServiceNetworkConfig{
@@ -36,4 +36,9 @@ func TestQueryServiceOpenAPI(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get(fmt.Sprintf("%s/metrics", c.URI))
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}