Files
query-orchestration/test/queryService/collectorservice_test.go
T
Michael McGuinness bbd86fb4ea Merged in feature/CollectorBuildVersion (pull request #100)
Collector Build Version

* lint

* fixtests
2025-03-11 18:15:49 +00:00

114 lines
3.2 KiB
Go

package endtoend
import (
"context"
"regexp"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue"
"queryorchestration/internal/test"
queryservice "queryorchestration/pkg/queryService"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
)
type CollectorConfig struct {
serviceconfig.BaseConfig
queue.QueueConfig
}
func TestCollectorService(t *testing.T) {
ctx := context.Background()
cfg := &CollectorConfig{}
test.SetCfgProviderWithBasePath(t, cfg, "../..")
network, ncleanup := test.CreateNetwork(t, ctx)
defer ncleanup()
_, clean := test.CreateAWSContainer(t, ctx, &test.CreateAWSConfig{
Cfg: cfg,
Network: network,
})
defer clean()
test.SetQueueClient(t, ctx, cfg)
clientsyncurl := test.CreateQueue(t, ctx, cfg, test.ClientSyncRunner)
c, cleanup := test.CreateServiceNetwork(t, ctx, &test.ServiceNetworkConfig{
Cfg: cfg,
Network: network,
Name: test.QueryService,
Env: map[string]string{
"CLIENT_SYNC_URL": clientsyncurl,
"QUERY_VERSION_SYNC_URL": "iamthere",
},
})
defer cleanup()
client, err := queryservice.NewClientWithResponses(c.URI)
assert.NoError(t, err)
contextRes, err := client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.CONTEXTFULL,
})
assert.NoError(t, err)
jsoncfg := "{\"path\":\"key\"}"
jsonRes, err := client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{
Type: queryservice.JSONEXTRACTOR,
Config: &jsoncfg,
RequiredQueries: &[]types.UUID{
contextRes.JSON201.Id,
},
})
assert.NoError(t, err)
clientRes, err := client.CreateClientWithResponse(ctx, queryservice.ClientCreate{
Name: "example_name",
Id: "ID",
})
assert.NoError(t, err)
id := clientRes.JSON201.Id
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
assert.NoError(t, err)
assert.Equal(t, id, collRes.JSON200.ClientId)
assert.Equal(t, int32(0), collRes.JSON200.ActiveVersion)
assert.Equal(t, int32(0), collRes.JSON200.LatestVersion)
assert.Equal(t, int64(0), collRes.JSON200.MinimumCleanerVersion)
assert.Equal(t, int64(0), collRes.JSON200.MinimumTextVersion)
assert.Len(t, collRes.JSON200.Fields, 0)
av := int32(1)
fields := []queryservice.CollectorField{
{
Name: "json",
QueryId: jsonRes.JSON201.Id,
},
}
minVersion := int64(1000)
uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryservice.CollectorSet{
ActiveVersion: &av,
MinimumCleanerVersion: &minVersion,
MinimumTextVersion: &minVersion,
Fields: &fields,
})
assert.NoError(t, err)
assert.Equal(t, 200, uRes.StatusCode())
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
assert.NoError(t, err)
assert.Equal(t, id, collRes.JSON200.ClientId)
assert.Equal(t, int32(1), collRes.JSON200.ActiveVersion)
assert.Equal(t, int32(1), collRes.JSON200.LatestVersion)
assert.Equal(t, minVersion, collRes.JSON200.MinimumCleanerVersion)
assert.Equal(t, minVersion, collRes.JSON200.MinimumTextVersion)
assert.Len(t, collRes.JSON200.Fields, 1)
assert.ElementsMatch(t, fields, collRes.JSON200.Fields)
test.AssertMessageBody(t, ctx, cfg, clientsyncurl, regexp.MustCompile(`{"id":".+"}`))
}