Add single-pipeline run entrypoint
This commit is contained in:
@@ -811,6 +811,83 @@ func TestBuildRunReportIncludesPartialFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipelineRunsOnlyRequestedPipeline(t *testing.T) {
|
||||
firstSource := t.TempDir()
|
||||
secondSource := t.TempDir()
|
||||
firstDestination := t.TempDir()
|
||||
secondDestination := t.TempDir()
|
||||
writeSourceBundle(t, firstSource, "", testBundleOptions{ID: "reports.one"})
|
||||
writeSourceBundle(t, secondSource, "", testBundleOptions{ID: "reports.two"})
|
||||
configPath := writeTwoPipelineConfig(t, firstSource, firstDestination, secondSource, secondDestination)
|
||||
notifier := &recordingNotifier{}
|
||||
|
||||
report, err := RunPipeline(context.Background(), RunPipelineOptions{
|
||||
ConfigPath: configPath,
|
||||
PipelineID: "reports-one",
|
||||
Notifier: notifier,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("RunPipeline() error = %v", err)
|
||||
}
|
||||
if got, want := len(report.Pipelines), 1; got != want {
|
||||
t.Fatalf("pipeline count = %d, want %d", got, want)
|
||||
}
|
||||
if report.Pipelines[0].ID != "reports-one" {
|
||||
t.Fatalf("pipeline id = %q, want reports-one", report.Pipelines[0].ID)
|
||||
}
|
||||
if got, want := len(report.Actions), 1; got != want {
|
||||
t.Fatalf("action count = %d, want %d", got, want)
|
||||
}
|
||||
if report.Actions[0].PipelineID != "reports-one" || report.Actions[0].Action != "publish_new" {
|
||||
t.Fatalf("action = %#v, want reports-one publish_new", report.Actions[0])
|
||||
}
|
||||
if got, want := len(notifier.events), 1; got != want {
|
||||
t.Fatalf("notification count = %d, want %d", got, want)
|
||||
}
|
||||
if notifier.events[0].PipelineID != "reports-one" {
|
||||
t.Fatalf("notification pipeline = %q, want reports-one", notifier.events[0].PipelineID)
|
||||
}
|
||||
testutil.AssertFile(t, filepath.Join(firstDestination, "report.md"), "# Report\nSunny.\n")
|
||||
if entries, err := os.ReadDir(secondDestination); err != nil || len(entries) != 0 {
|
||||
t.Fatalf("second destination entries = %v err=%v, want empty", entries, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipelineUnknownIDReturnsNotFound(t *testing.T) {
|
||||
sourceRoot := t.TempDir()
|
||||
destinationRoot := t.TempDir()
|
||||
writeSourceBundle(t, sourceRoot, "", testBundleOptions{})
|
||||
|
||||
_, err := RunPipeline(context.Background(), RunPipelineOptions{
|
||||
ConfigPath: writeLocalConfig(t, sourceRoot, destinationRoot),
|
||||
PipelineID: "missing",
|
||||
})
|
||||
if err == nil || !IsPipelineNotFound(err) {
|
||||
t.Fatalf("RunPipeline() error = %v, want pipeline not found", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), `pipeline "missing" not found`) {
|
||||
t.Fatalf("RunPipeline() error = %v, want pipeline id in message", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunStillRunsAllConfiguredPipelines(t *testing.T) {
|
||||
firstSource := t.TempDir()
|
||||
secondSource := t.TempDir()
|
||||
firstDestination := t.TempDir()
|
||||
secondDestination := t.TempDir()
|
||||
writeSourceBundle(t, firstSource, "", testBundleOptions{ID: "reports.one"})
|
||||
writeSourceBundle(t, secondSource, "", testBundleOptions{ID: "reports.two"})
|
||||
|
||||
err := Run(context.Background(), RunOptions{
|
||||
ConfigPath: writeTwoPipelineConfig(t, firstSource, firstDestination, secondSource, secondDestination),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
testutil.AssertFile(t, filepath.Join(firstDestination, "report.md"), "# Report\nSunny.\n")
|
||||
testutil.AssertFile(t, filepath.Join(secondDestination, "report.md"), "# Report\nSunny.\n")
|
||||
}
|
||||
|
||||
func TestRunDoesNotNotifyForSkippedDestination(t *testing.T) {
|
||||
sourceRoot := t.TempDir()
|
||||
destinationRoot := t.TempDir()
|
||||
@@ -1439,6 +1516,29 @@ func writeFanoutConfig(t *testing.T, sourceRoot, firstDestination, secondDestina
|
||||
return testutil.WriteFanoutLocalConfig(t, sourceRoot, firstDestination, secondDestination)
|
||||
}
|
||||
|
||||
func writeTwoPipelineConfig(t *testing.T, firstSource, firstDestination, secondSource, secondDestination string) string {
|
||||
t.Helper()
|
||||
return writeConfigFile(t, `
|
||||
pipelines:
|
||||
- id: reports-one
|
||||
source:
|
||||
backend: local
|
||||
path: `+firstSource+`
|
||||
destinations:
|
||||
- id: archive
|
||||
backend: local
|
||||
path: `+firstDestination+`
|
||||
- id: reports-two
|
||||
source:
|
||||
backend: local
|
||||
path: `+secondSource+`
|
||||
destinations:
|
||||
- id: archive
|
||||
backend: local
|
||||
path: `+secondDestination+`
|
||||
`)
|
||||
}
|
||||
|
||||
func writeConfigFile(t *testing.T, body string) string {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), "config.yml")
|
||||
|
||||
Reference in New Issue
Block a user