32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package workflow
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
|
)
|
|
|
|
type failingSnapshotSource struct{ PRSource }
|
|
|
|
func (failingSnapshotSource) Snapshot(context.Context, string, string, int, string) (string, error) {
|
|
return "", errors.New("forge unreachable")
|
|
}
|
|
|
|
// A pr-review run that stops after anatomy must not leave its snapshot behind.
|
|
func TestPRReviewRemovesSnapshotOnEarlyStop(t *testing.T) {
|
|
tc := &TaskContext{Task: &task.Task{ID: 7}, PRSource: failingSnapshotSource{}, prReview: &prReviewState{}}
|
|
stage := stagePRReviewAndOpenPR([]Stage{stagePRAnatomy()}, func(*TaskContext) string { return "" })
|
|
if err := stage.Run(context.Background(), tc); err == nil {
|
|
t.Fatal("expected the snapshot failure to stop the run")
|
|
}
|
|
if tc.prReview.snapshotDir == "" {
|
|
t.Fatal("anatomy did not create a snapshot directory")
|
|
}
|
|
if _, err := os.Stat(tc.prReview.snapshotDir); !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("snapshot directory %s still exists", tc.prReview.snapshotDir)
|
|
}
|
|
}
|