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

77 lines
2.4 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/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.
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)
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)
av := int32(1)
minVersion := int64(1000)
uRes, err := client.SetCollectorByClientIdWithResponse(ctx, id, queryapi.CollectorSet{
ActiveVersion: &av,
MinimumCleanerVersion: &minVersion,
MinimumTextVersion: &minVersion,
})
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)
test.AssertMessageBody(t, cfg, c.Dependencies.QueueURLs[test.ClientSyncRunnerName], regexp.MustCompile(`{"id":".+"}`))
}