Give each CLI run its own invocation lifecycle
This commit is contained in:
40
internal/cli/run_invocation_test.go
Normal file
40
internal/cli/run_invocation_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
func TestRunInvocationFinalizationPreservesCausesAndPublishedLocations(t *testing.T) {
|
||||
capture, err := frameworkdebug.Start(t.TempDir(), "run", time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
primary, captureFailure := errors.New("pipeline failed"), errors.New("capture failed")
|
||||
capture.RecordError(captureFailure)
|
||||
outputPath := filepath.Join(t.TempDir(), "output")
|
||||
run := &runInvocation{capture: capture, outputDirectory: outputPath, published: true}
|
||||
outcome := run.finish(commandkit.Failure("pipeline failed").WithCause(primary))
|
||||
if outcome.Status == 0 || !errors.Is(outcome.Cause, primary) || !errors.Is(outcome.Cause, captureFailure) {
|
||||
t.Fatalf("outcome = %#v, want both causes", outcome)
|
||||
}
|
||||
if !strings.Contains(outcome.Explanation.Message, outputPath) || !strings.Contains(outcome.Explanation.Message, capture.Path()) {
|
||||
t.Fatalf("failure does not retain published locations: %s", outcome.Explanation.Message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunInvocationFailureDoesNotClaimUnpublishedOutput(t *testing.T) {
|
||||
outputPath := filepath.Join(t.TempDir(), "output")
|
||||
run := &runInvocation{outputDirectory: outputPath}
|
||||
cause := errors.New("preparation failed")
|
||||
outcome := run.finish(commandkit.Failure("preparation failed").WithCause(cause))
|
||||
if !errors.Is(outcome.Cause, cause) || strings.Contains(outcome.Explanation.Message, outputPath) {
|
||||
t.Fatalf("outcome = %#v, want cause without unpublished location", outcome)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user