Files
query-orchestration/internal/test/api.go
T
Jay Brown 35d72fccbe Merged in feature/remove-mocks (pull request #202)
Feature/remove mocks

* remove mocks

* cleanup db migrations
2026-01-15 20:39:32 +00:00

73 lines
1.6 KiB
Go

package test
import (
"context"
"fmt"
"io"
"net/http"
"testing"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type APIName string
const (
QueryAPIName APIName = "queryAPI"
)
type API struct {
Name APIName
DownstreamQueues []RunnerName
}
type APIConfig struct {
API API
}
func CreateAPI(t testing.TB, ctx context.Context, cfg ContainerConfigProvider, network string, config *APIConfig) (*Container, func()) {
port, err := nat.NewPort("tcp", "8080")
require.NoError(t, err)
container, cleanup := createContainer(t, ctx, network, &containerConfig{
Cfg: cfg,
Name: string(config.API.Name),
DownstreamQueues: config.API.DownstreamQueues,
WaitForMsg: "⇨ http server started on [::]:8080",
})
host, err := container.Host(ctx)
require.NoError(t, err)
mappedPort, err := container.MappedPort(ctx, port)
require.NoError(t, err)
address := fmt.Sprintf("http://%s:%s", host, mappedPort.Port())
return &Container{
URI: address,
Container: container,
}, cleanup
}
// QueryAPI configuration. Query processing has been removed - only client sync remains.
var QueryAPI = API{
Name: QueryAPIName,
DownstreamQueues: []RunnerName{
ClientSyncRunnerName,
},
}
var apis = []API{
QueryAPI,
}
func AssertStatus(t testing.TB, statusCode int, response *http.Response) {
if !assert.Equal(t, statusCode, response.StatusCode) && response.Body != nil {
response, err := io.ReadAll(response.Body)
require.NoError(t, err)
t.Log("response: ", string(response))
}
}