package endtoend_test import ( "net/http" "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/stretchr/testify/assert" ) type Config struct { serviceconfig.BaseConfig aws.AWSConfig queue.QueueConfig objectstore.ObjectStoreConfig } // TestCollectorService tests the collector API endpoints. // Note: Query functionality has been removed. See remove_query_plan.md for details. // Note: MinimumTextVersion has been removed since text extraction is deprecated. func TestCollectorService(t *testing.T) { ctx := t.Context() cfg := &Config{} c, cleanup := test.CreateAPINetwork(t, ctx, cfg, test.QueryAPI) defer cleanup() client, err := queryapi.NewClientWithResponses(c.API.URI) 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) 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) av := int32(1) minVersion := int64(1000) uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryapi.CollectorSet{ ActiveVersion: &av, MinimumCleanerVersion: &minVersion, }) require.NoError(t, err) test.AssertStatus(t, http.StatusOK, uRes.HTTPResponse) collRes, err = client.GetCollectorByClientIdWithResponse(ctx, id) 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) test.AssertMessageBody(t, cfg, c.Dependencies.QueueURLs[test.ClientSyncRunnerName], regexp.MustCompile(`{"id":".+"}`)) }