Files
query-orchestration/test/queryAPI/collectorservice_test.go
T
Michael McGuinness fee71e7740 Merged in feature/postprocessing (pull request #114)
Feature/postprocessing

* tests

* passtest

* fixshorttests

* mosttests

* improvingbasedockerfile

* testspeeds

* testing

* host

* canparallel

* clean

* passfullsuite

* singlepagemax

* test

* findfeatures

* findstables

* tbls

* tablestoo

* tablestoo

* lateraltests

* tableloc

* cleanup

* inlinetable

* childids

* cleanup

* tests
2025-04-22 14:40:16 +00:00

100 lines
2.9 KiB
Go

package endtoend_test
import (
"context"
"regexp"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/aws"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/serviceconfig/queue"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/stretchr/testify/require"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
)
type Config struct {
serviceconfig.BaseConfig
aws.AWSConfig
queue.QueueConfig
objectstore.ObjectStoreConfig
}
func TestCollectorService(t *testing.T) {
ctx := context.Background()
cfg := &Config{}
test.SetCfgProvider(t, cfg)
c, cleanup := test.CreateAPINetwork(t, ctx, cfg, test.QueryAPI)
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.API.URI)
require.NoError(t, err)
contextRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
})
require.NoError(t, err)
jsoncfg := "{\"path\":\"key\"}"
jsonRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.JSONEXTRACTOR,
Config: &jsoncfg,
RequiredQueries: &[]types.UUID{
contextRes.JSON201.Id,
},
})
require.NoError(t, err)
clientRes, err := client.CreateClientWithResponse(ctx, queryapi.ClientCreate{
Name: "example_name",
Id: "ID",
})
require.NoError(t, err)
id := clientRes.JSON201.Id
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
require.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 := []queryapi.CollectorField{
{
Name: "json",
QueryId: jsonRes.JSON201.Id,
},
}
minVersion := int64(1000)
uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryapi.CollectorSet{
ActiveVersion: &av,
MinimumCleanerVersion: &minVersion,
MinimumTextVersion: &minVersion,
Fields: &fields,
})
require.NoError(t, err)
assert.Equal(t, 200, uRes.StatusCode())
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
require.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, c.Dependencies.QueueURLs[test.ClientSyncRunnerName], regexp.MustCompile(`{"id":".+"}`))
}