40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
|
)
|
|
|
|
func TestRunnerCancellationRetainsDrainedCaptureFailure(t *testing.T) {
|
|
for _, stage := range []string{"extract", "merge", "normalize"} {
|
|
t.Run(stage, func(t *testing.T) {
|
|
prepared := preparedConcurrentPipeline(t, 1)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
cause := errors.New("operation outcome capture failed")
|
|
writes := 0
|
|
writer := &nativeEvidence{fail: func(name string) error {
|
|
if strings.Contains(name, "/"+stage+"/") && strings.HasSuffix(name, "/outcome.json") {
|
|
writes++
|
|
cancel()
|
|
return cause
|
|
}
|
|
return nil
|
|
}}
|
|
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 1,
|
|
Execution: contracts.ExecutionOptions{Capture: writer}})
|
|
var captured *contracts.CaptureError
|
|
if !errors.Is(err, context.Canceled) || !errors.Is(err, cause) || !errors.As(err, &captured) {
|
|
t.Fatalf("Run() error = %v, want cancellation and capture cause/type", err)
|
|
}
|
|
if writes != 1 || len(output.OutputFiles) != 0 || output.FallbackCount != 0 {
|
|
t.Fatalf("writes=%d files=%d fallbacks=%d", writes, len(output.OutputFiles), output.FallbackCount)
|
|
}
|
|
})
|
|
}
|
|
}
|