Files
query-orchestration/test/queryAPI/collectorservice_test.go
T

101 lines
3.0 KiB
Go
Raw Normal View History

package endtoend_test
import (
"net/http"
2025-03-05 12:05:46 +00:00
"regexp"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/aws"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/serviceconfig/queue"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
2025-03-19 11:54:14 +00:00
"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) {
2025-06-03 13:52:10 +00:00
ctx := t.Context()
cfg := &Config{}
c, cleanup := test.CreateAPINetwork(t, ctx, cfg, test.QueryAPI)
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.API.URI)
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
contextRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
})
2025-03-19 11:54:14 +00:00
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,
},
})
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
clientRes, err := client.CreateClientWithResponse(ctx, queryapi.ClientCreate{
Name: "example_name",
Id: "ID",
})
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
id := clientRes.JSON201.Id
collRes, err := client.GetCollectorByClientIdWithResponse(ctx, id)
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
test.AssertStatus(t, http.StatusOK, collRes.HTTPResponse)
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,
})
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
test.AssertStatus(t, http.StatusOK, uRes.HTTPResponse)
collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id)
2025-03-19 11:54:14 +00:00
require.NoError(t, err)
test.AssertStatus(t, http.StatusOK, collRes.HTTPResponse)
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, cfg, c.Dependencies.QueueURLs[test.ClientSyncRunnerName], regexp.MustCompile(`{"id":".+"}`))
}