0df3d16976
Query Version Sync Runner * testing * queryversiosyncworking * update * tests * fixtests
108 lines
3.0 KiB
Go
108 lines
3.0 KiB
Go
package endtoend_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/serviceconfig"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
"queryorchestration/internal/test"
|
|
queryservice "queryorchestration/pkg/queryService"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/oapi-codegen/runtime/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type QueryConfig struct {
|
|
serviceconfig.BaseConfig
|
|
queue.QueueConfig
|
|
}
|
|
|
|
func TestQueryService(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
cfg := &QueryConfig{}
|
|
test.SetCfgProvider(t, cfg)
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../.."))
|
|
|
|
network, ncleanup := test.CreateNetwork(t, ctx)
|
|
defer ncleanup()
|
|
|
|
_, clean := test.CreateAWSContainer(t, ctx, &test.CreateAWSConfig{
|
|
Cfg: cfg,
|
|
Network: network,
|
|
})
|
|
defer clean()
|
|
|
|
err := cfg.SetQueueClient(ctx)
|
|
assert.NoError(t, err)
|
|
queryversionsyncurl := test.CreateQueue(t, ctx, cfg, test.QueryVersionSyncRunner)
|
|
|
|
c, cleanup := test.CreateServiceNetwork(t, ctx, &test.ServiceNetworkConfig{
|
|
Cfg: cfg,
|
|
Network: network,
|
|
Name: test.QueryService,
|
|
Env: map[string]string{
|
|
"JOB_SYNC_URL": "/i/am/here",
|
|
"QUERY_VERSION_SYNC_URL": queryversionsyncurl,
|
|
},
|
|
})
|
|
defer cleanup()
|
|
|
|
client, err := queryservice.NewClientWithResponses(c.URI)
|
|
assert.NoError(t, err)
|
|
|
|
idRes, err := client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
|
|
Type: queryservice.CONTEXTFULL,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, idRes)
|
|
assert.NotNil(t, idRes.JSON201)
|
|
contextID := idRes.JSON201.Id
|
|
assert.NotEmpty(t, contextID)
|
|
|
|
jcfg := "{}"
|
|
idRes, err = client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
|
|
Type: queryservice.JSONEXTRACTOR,
|
|
Config: &jcfg,
|
|
})
|
|
assert.NoError(t, err)
|
|
jsonID := idRes.JSON201.Id
|
|
|
|
queryRes, err := client.GetQueryWithResponse(ctx, jsonID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, jsonID, queryRes.JSON200.Id)
|
|
assert.Equal(t, queryservice.JSONEXTRACTOR, queryRes.JSON200.Type)
|
|
assert.Equal(t, int32(1), queryRes.JSON200.ActiveVersion)
|
|
assert.Equal(t, int32(1), queryRes.JSON200.LatestVersion)
|
|
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
|
|
assert.Nil(t, queryRes.JSON200.RequiredQueries)
|
|
|
|
queriesRes, err := client.ListQueriesWithResponse(ctx)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, queriesRes.JSON200.Queries, 2)
|
|
|
|
aV := int32(2)
|
|
res, err := client.UpdateQueryWithResponse(ctx, jsonID, queryservice.QueryUpdate{
|
|
ActiveVersion: &aV,
|
|
RequiredQueries: &[]types.UUID{
|
|
contextID,
|
|
},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, res)
|
|
|
|
test.AssertMessageBody(t, ctx, cfg, queryversionsyncurl, regexp.MustCompile(`{"id":".+"}`))
|
|
|
|
queryRes, err = client.GetQueryWithResponse(ctx, jsonID)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, jsonID, queryRes.JSON200.Id)
|
|
assert.Equal(t, queryservice.JSONEXTRACTOR, queryRes.JSON200.Type)
|
|
assert.Equal(t, int32(2), queryRes.JSON200.ActiveVersion)
|
|
assert.Equal(t, int32(2), queryRes.JSON200.LatestVersion)
|
|
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
|
|
assert.ElementsMatch(t, []types.UUID{contextID}, *queryRes.JSON200.RequiredQueries)
|
|
}
|