All checks were successful
ci/woodpecker/tag/release Pipeline was successful
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolvePipelineConfigPathWithCandidatesExplicitWins(t *testing.T) {
|
|
got, err := resolvePipelineConfigPathWithCandidates(" ./custom/pipeline.yml ", []string{"/a", "/b"})
|
|
if err != nil {
|
|
t.Fatalf("resolvePipelineConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != "./custom/pipeline.yml" {
|
|
t.Fatalf("resolved path = %q, want explicit path", got)
|
|
}
|
|
}
|
|
|
|
func TestResolvePipelineConfigPathWithCandidatesUsesFirstExisting(t *testing.T) {
|
|
dir := t.TempDir()
|
|
first := filepath.Join(dir, "first.yml")
|
|
second := filepath.Join(dir, "second.yml")
|
|
if err := os.WriteFile(second, []byte("workspace:\n root: ./tmp\n"), 0o644); err != nil {
|
|
t.Fatalf("write second default: %v", err)
|
|
}
|
|
|
|
got, err := resolvePipelineConfigPathWithCandidates("", []string{first, second})
|
|
if err != nil {
|
|
t.Fatalf("resolvePipelineConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != filepath.Clean(second) {
|
|
t.Fatalf("resolved path = %q, want %q", got, filepath.Clean(second))
|
|
}
|
|
}
|
|
|
|
func TestResolvePipelineConfigPathWithCandidatesPrecedence(t *testing.T) {
|
|
dir := t.TempDir()
|
|
first := filepath.Join(dir, "first.yml")
|
|
second := filepath.Join(dir, "second.yml")
|
|
if err := os.WriteFile(first, []byte("workspace:\n root: ./tmp\n"), 0o644); err != nil {
|
|
t.Fatalf("write first default: %v", err)
|
|
}
|
|
if err := os.WriteFile(second, []byte("workspace:\n root: ./tmp\n"), 0o644); err != nil {
|
|
t.Fatalf("write second default: %v", err)
|
|
}
|
|
|
|
got, err := resolvePipelineConfigPathWithCandidates("", []string{first, second})
|
|
if err != nil {
|
|
t.Fatalf("resolvePipelineConfigPathWithCandidates() error = %v", err)
|
|
}
|
|
if got != filepath.Clean(first) {
|
|
t.Fatalf("resolved path = %q, want first candidate %q", got, filepath.Clean(first))
|
|
}
|
|
}
|
|
|
|
func TestResolvePipelineConfigPathWithCandidatesMissing(t *testing.T) {
|
|
_, err := resolvePipelineConfigPathWithCandidates("", []string{"/does/not/exist/one.yml", "/does/not/exist/two.yml"})
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), "no default pipeline config found") {
|
|
t.Fatalf("error = %q, want missing-defaults context", err.Error())
|
|
}
|
|
}
|