Merged in feature/docresult (pull request #105)

Document Result Endpoint

* testing

* cleantesting

* progress

* query

* lint

* readme

* dockerclient

* api

* passtest

* tests

* test
This commit is contained in:
Michael McGuinness
2025-03-17 18:14:15 +00:00
parent f7c41c4ef3
commit 555b6d420b
105 changed files with 3276 additions and 2484 deletions
+41
View File
@@ -0,0 +1,41 @@
package endtoend_test
import (
"context"
"fmt"
"net/http"
"testing"
"queryorchestration/internal/test"
"github.com/stretchr/testify/assert"
)
func TestQueryAPIAccessories(t *testing.T) {
ctx := context.Background()
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
API: test.QueryAPI,
})
defer cleanup()
resp, err := http.Get(fmt.Sprintf("%s/swagger/doc.json", c.URI))
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get(fmt.Sprintf("%s/swagger/doc.yaml", c.URI))
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get(fmt.Sprintf("%s/swagger/index.html", c.URI))
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get(fmt.Sprintf("%s/metrics", c.URI))
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}
+54
View File
@@ -0,0 +1,54 @@
package endtoend
import (
"context"
"testing"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/stretchr/testify/assert"
)
func TestClient(t *testing.T) {
ctx := context.Background()
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
API: test.QueryAPI,
})
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.URI)
assert.NoError(t, err)
idRes, err := client.CreateClientWithResponse(ctx, queryapi.ClientCreate{
Name: "example_name",
Id: "EXA",
})
assert.NoError(t, err)
assert.NotNil(t, idRes)
assert.NotNil(t, idRes.JSON201)
assert.NotNil(t, idRes.JSON201.Id)
id := idRes.JSON201.Id
clientRes, err := client.GetClientWithResponse(ctx, id)
assert.NoError(t, err)
assert.Equal(t, id, clientRes.JSON200.Id)
assert.Equal(t, "example_name", clientRes.JSON200.Name)
assert.False(t, clientRes.JSON200.CanSync)
updateName := "update_name"
updateCanSync := true
updateRes, err := client.UpdateClientWithResponse(ctx, id, queryapi.ClientUpdate{
Name: &updateName,
CanSync: &updateCanSync,
})
assert.NoError(t, err)
assert.NotNil(t, updateRes)
clientRes, err = client.GetClientWithResponse(ctx, id)
assert.NoError(t, err)
assert.Equal(t, id, clientRes.JSON200.Id)
assert.Equal(t, updateName, clientRes.JSON200.Name)
assert.True(t, clientRes.JSON200.CanSync)
}
+109
View File
@@ -0,0 +1,109 @@
package endtoend
import (
"context"
"regexp"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
"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.ClientSyncRunnerName)
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
Cfg: cfg,
Network: network,
API: test.QueryAPI,
})
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.URI)
assert.NoError(t, err)
contextRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
})
assert.NoError(t, err)
jsoncfg := "{\"path\":\"key\"}"
jsonRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.JSONEXTRACTOR,
Config: &jsoncfg,
RequiredQueries: &[]types.UUID{
contextRes.JSON201.Id,
},
})
assert.NoError(t, err)
clientRes, err := client.CreateClientWithResponse(ctx, queryapi.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 := []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,
})
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":".+"}`))
}
+27
View File
@@ -0,0 +1,27 @@
package endtoend
import (
"context"
"testing"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/stretchr/testify/assert"
)
func TestExportService(t *testing.T) {
ctx := context.Background()
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
API: test.QueryAPI,
})
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.URI)
assert.NoError(t, err)
idRes, err := client.TriggerExportWithResponse(ctx, "CLIENT_ID", queryapi.ExportTrigger{})
assert.NoError(t, err)
assert.NotNil(t, idRes)
}
+104
View File
@@ -0,0 +1,104 @@
package endtoend_test
import (
"context"
"os"
"path"
"regexp"
"testing"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue"
"queryorchestration/internal/test"
queryapi "queryorchestration/pkg/queryAPI"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
)
type QueryConfig struct {
serviceconfig.BaseConfig
queue.QueueConfig
}
func TestQueryAPI(t *testing.T) {
ctx := context.Background()
cfg := &QueryConfig{}
test.SetCfgProvider(t, cfg)
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../.."))
network, ncleanup := test.CreateNetwork(t, ctx)
defer ncleanup()
_, clean := test.CreateAWSContainer(t, ctx, &test.CreateAWSConfig{
Cfg: cfg,
Network: network,
})
defer clean()
err := cfg.SetQueueClient(ctx)
assert.NoError(t, err)
queryversionsyncurl := test.CreateQueue(t, ctx, cfg, test.QueryVersionSyncRunnerName)
c, cleanup := test.CreateAPINetwork(t, ctx, &test.ServiceNetworkConfig{
Cfg: cfg,
Network: network,
API: test.QueryAPI,
})
defer cleanup()
client, err := queryapi.NewClientWithResponses(c.URI)
assert.NoError(t, err)
idRes, err := client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
})
assert.NoError(t, err)
assert.NotNil(t, idRes)
assert.NotNil(t, idRes.JSON201)
contextID := idRes.JSON201.Id
assert.NotEmpty(t, contextID)
jcfg := "{}"
idRes, err = client.CreateQueryWithResponse(ctx, queryapi.QueryCreate{
Type: queryapi.JSONEXTRACTOR,
Config: &jcfg,
})
assert.NoError(t, err)
jsonID := idRes.JSON201.Id
queryRes, err := client.GetQueryWithResponse(ctx, jsonID)
assert.NoError(t, err)
assert.Equal(t, jsonID, queryRes.JSON200.Id)
assert.Equal(t, queryapi.JSONEXTRACTOR, queryRes.JSON200.Type)
assert.Equal(t, int32(1), queryRes.JSON200.ActiveVersion)
assert.Equal(t, int32(1), queryRes.JSON200.LatestVersion)
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
assert.Nil(t, queryRes.JSON200.RequiredQueries)
queriesRes, err := client.ListQueriesWithResponse(ctx)
assert.NoError(t, err)
assert.Len(t, queriesRes.JSON200.Queries, 2)
aV := int32(2)
res, err := client.UpdateQueryWithResponse(ctx, jsonID, queryapi.QueryUpdate{
ActiveVersion: &aV,
RequiredQueries: &[]types.UUID{
contextID,
},
})
assert.NoError(t, err)
assert.NotNil(t, res)
test.AssertMessageBody(t, ctx, cfg, queryversionsyncurl, regexp.MustCompile(`{"id":".+"}`))
queryRes, err = client.GetQueryWithResponse(ctx, jsonID)
assert.NoError(t, err)
assert.Equal(t, jsonID, queryRes.JSON200.Id)
assert.Equal(t, queryapi.JSONEXTRACTOR, queryRes.JSON200.Type)
assert.Equal(t, int32(2), queryRes.JSON200.ActiveVersion)
assert.Equal(t, int32(2), queryRes.JSON200.LatestVersion)
assert.Equal(t, jcfg, *queryRes.JSON200.Config)
assert.ElementsMatch(t, []types.UUID{contextID}, *queryRes.JSON200.RequiredQueries)
}