Files
query-orchestration/internal/test/runner.go
T

126 lines
3.7 KiB
Go
Raw Normal View History

// Package test provides test utilities and infrastructure.
// Note: Text extraction has been removed. DocTextRunner is no longer part of the pipeline.
// The document processing pipeline now ends at DocCleanRunner.
// See remove_texttract_and_mocks_plan.md for details.
package test
import (
"context"
2025-03-05 12:05:46 +00:00
"testing"
"queryorchestration/internal/serviceconfig/queue/clientsync"
"queryorchestration/internal/serviceconfig/queue/documentclean"
"queryorchestration/internal/serviceconfig/queue/documentinit"
"queryorchestration/internal/serviceconfig/queue/documentsync"
"queryorchestration/internal/serviceconfig/queue/storeevent"
)
// RunnerName defines the name of a runner service.
type RunnerName string
const (
StoreEventRunnerName RunnerName = "storeEventRunner"
DocInitRunnerName RunnerName = "docInitRunner"
DocSyncRunnerName RunnerName = "docSyncRunner"
DocCleanRunnerName RunnerName = "docCleanRunner"
ClientSyncRunnerName RunnerName = "clientSyncRunner"
)
// RunnerEnv defines the environment variable name for a runner queue.
type RunnerEnv string
const (
StoreEventRunnerEnv RunnerEnv = storeevent.EnvName
DocInitRunnerEnv RunnerEnv = documentinit.EnvName
DocSyncRunnerEnv RunnerEnv = documentsync.EnvName
DocCleanRunnerEnv RunnerEnv = documentclean.EnvName
ClientSyncRunnerEnv RunnerEnv = clientsync.EnvName
)
// Runner represents a runner service configuration.
type Runner struct {
Name RunnerName
DownstreamQueues []RunnerName
}
// GetRunnerEnvFromName returns the environment variable name for a given runner.
func GetRunnerEnvFromName(name RunnerName) RunnerEnv {
switch name {
case StoreEventRunnerName:
return StoreEventRunnerEnv
case DocInitRunnerName:
return DocInitRunnerEnv
case DocSyncRunnerName:
return DocSyncRunnerEnv
case DocCleanRunnerName:
return DocCleanRunnerEnv
case ClientSyncRunnerName:
return ClientSyncRunnerEnv
}
return DocInitRunnerEnv
}
// RunnerConfig provides configuration for creating a runner container.
type RunnerConfig struct {
Runner Runner
}
// CreateRunner creates a runner container for testing.
func CreateRunner(t testing.TB, ctx context.Context, cfg ContainerConfigProvider, network string, config *RunnerConfig) (*Container, func()) {
env := map[string]string{}
2025-04-25 17:02:50 +00:00
url := GetQueueURL(t, cfg, config.Runner.Name)
env["QUEUE_URL"] = url
c, cleanup := createContainer(t, ctx, network, &containerConfig{
Name: string(config.Runner.Name),
DownstreamQueues: config.Runner.DownstreamQueues,
Cfg: cfg,
Env: env,
WaitForMsg: "Listening to queue",
})
return &Container{
Container: c,
URI: url,
}, cleanup
}
// StoreEventRunner configuration.
var StoreEventRunner = Runner{
Name: StoreEventRunnerName,
DownstreamQueues: []RunnerName{DocInitRunnerName},
}
// DocInitRunner configuration.
var DocInitRunner = Runner{
Name: DocInitRunnerName,
DownstreamQueues: []RunnerName{DocSyncRunnerName},
}
// DocSyncRunner configuration.
var DocSyncRunner = Runner{
Name: DocSyncRunnerName,
DownstreamQueues: []RunnerName{DocCleanRunnerName},
}
// DocCleanRunner is the terminal runner in the main document processing pipeline.
// Note: Text extraction has been removed. Pipeline ends after cleaning.
var DocCleanRunner = Runner{
Name: DocCleanRunnerName,
DownstreamQueues: []RunnerName{}, // No downstream - pipeline ends here
}
// ClientSyncRunner configuration.
var ClientSyncRunner = Runner{
Name: ClientSyncRunnerName,
DownstreamQueues: []RunnerName{DocSyncRunnerName},
}
var runners = []Runner{
StoreEventRunner,
DocInitRunner,
DocSyncRunner,
DocCleanRunner,
ClientSyncRunner,
}