72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package notarius
|
|
|
|
import (
|
|
"context"
|
|
|
|
configkit "go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
// FakeRunner is a configurable in-memory runner for stage tests.
|
|
type FakeRunner struct {
|
|
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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
copyRequest := req
|
|
copyRequest.Credentials = append([]configkit.Secret(nil), req.Credentials...)
|
|
if req.ConfigOverlay != nil {
|
|
profile := *req.ConfigOverlay
|
|
copyRequest.ConfigOverlay = &profile
|
|
}
|
|
if req.Cache != nil {
|
|
cache := *req.Cache
|
|
copyRequest.Cache = &cache
|
|
}
|
|
copyRequest.References = append([]ReferenceBinding(nil), req.References...)
|
|
f.Requests = append(f.Requests, copyRequest)
|
|
if f.Err != nil {
|
|
return RunResult{}, f.Err
|
|
}
|
|
return f.Result, nil
|
|
}
|