Files

72 lines
2.3 KiB
Go
Raw Permalink Normal View History

2026-08-09 23:47:38 +00:00
package notarius
2026-09-25 15:33:46 +00:00
import (
"context"
configkit "go.maximumdirect.net/configkit"
2026-09-25 15:33:46 +00:00
)
2026-08-09 23:47:38 +00:00
// FakeRunner is a configurable in-memory runner for stage tests.
type FakeRunner struct {
2026-11-30 01:17:33 +00:00
Requests []RunRequest
Result RunResult
Err error
PreflightRequests []ReadinessRequest
PreflightResult *ReadinessResult
PreflightErr error
}
// Preflight records a request and returns a configurable native assessment.
func (f *FakeRunner) Preflight(ctx context.Context, req ReadinessRequest) (ReadinessResult, error) {
if err := ctx.Err(); err != nil {
return ReadinessResult{}, err
}
copyRequest := req
copyRequest.RequiredLanes = append([]string(nil), req.RequiredLanes...)
copyRequest.References = append([]ReferenceBinding(nil), req.References...)
copyRequest.Credentials = append([]configkit.Secret(nil), req.Credentials...)
if req.Cache != nil {
value := *req.Cache
copyRequest.Cache = &value
}
if req.ConfigOverlay != nil {
value := *req.ConfigOverlay
copyRequest.ConfigOverlay = &value
}
f.PreflightRequests = append(f.PreflightRequests, copyRequest)
if f.PreflightResult != nil {
result := *f.PreflightResult
if result.InputDescription == "" {
result.InputDescription = req.InputDescription
}
if result.InputPath == "" {
result.InputPath = req.InputPath
}
return result, f.PreflightErr
}
return ReadinessResult{Pipeline: req.PipelineID, Lanes: append([]string(nil), req.RequiredLanes...), InspectionComplete: true, AssessmentComplete: true, Ready: true, InputDescription: req.InputDescription, InputPath: req.InputPath}, f.PreflightErr
2026-08-09 23:47:38 +00:00
}
// Run records the request and returns the configured result or error.
func (f *FakeRunner) Run(ctx context.Context, req RunRequest) (RunResult, error) {
if err := ctx.Err(); err != nil {
return RunResult{}, err
}
2026-08-29 15:16:06 +00:00
copyRequest := req
2026-09-25 15:33:46 +00:00
copyRequest.Credentials = append([]configkit.Secret(nil), req.Credentials...)
2026-09-28 03:09:55 +00:00
if req.ConfigOverlay != nil {
profile := *req.ConfigOverlay
copyRequest.ConfigOverlay = &profile
}
if req.Cache != nil {
cache := *req.Cache
copyRequest.Cache = &cache
}
2026-08-29 15:16:06 +00:00
copyRequest.References = append([]ReferenceBinding(nil), req.References...)
f.Requests = append(f.Requests, copyRequest)
2026-08-09 23:47:38 +00:00
if f.Err != nil {
return RunResult{}, f.Err
}
return f.Result, nil
}