Check expected publication push URL
This commit is contained in:
@@ -94,6 +94,103 @@ func TestPublishPushesOnlyTheCapturedAnnotatedTag(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishRejectsUnexpectedPushURLBeforeValidation(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
suiteRuns := filepath.Join(t.TempDir(), "suite-runs")
|
||||
t.Setenv("RELEASEKIT_FIXTURE_SUITE_RUNS", suiteRuns)
|
||||
expected := repo.bare + string(os.PathSeparator)
|
||||
var callbacks int
|
||||
result, err := releasekit.Publish(context.Background(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repo.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
ExpectedPushURL: expected,
|
||||
AdditionalChecks: func(context.Context, releasekit.Candidate) error {
|
||||
callbacks++
|
||||
return nil
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, releasekit.ErrUnexpectedPushURL) {
|
||||
t.Fatalf("Publish() error = %v, want ErrUnexpectedPushURL", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), fmt.Sprintf("expected %q", expected)) || !strings.Contains(err.Error(), fmt.Sprintf("resolved %q", repo.bare)) {
|
||||
t.Fatalf("Publish() error = %v, want expected and resolved URLs", err)
|
||||
}
|
||||
if result.State != releasekit.PublicationNotAttempted || result.Phase != releasekit.PublicationPreflight || result.Endpoint != repo.bare || result.TagObject != "" {
|
||||
t.Fatalf("publication result = %#v, want preflight failure at resolved endpoint", result)
|
||||
}
|
||||
if callbacks != 0 {
|
||||
t.Fatalf("additional checks ran %d times, want none", callbacks)
|
||||
}
|
||||
if _, statErr := os.Stat(suiteRuns); !errors.Is(statErr, os.ErrNotExist) {
|
||||
t.Fatalf("standard-suite marker stat error = %v, want no suite run", statErr)
|
||||
}
|
||||
if got := gitText(t, repo.work, "tag", "--list", "v1.2.3"); got != "" {
|
||||
t.Fatalf("local tag exists after URL mismatch: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishComparesExpectedURLWithResolvedInsteadOfDestination(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
alias := "releasekit-expected-push:"
|
||||
gitRun(t, repo.work, "config", "url."+repo.bare+".insteadOf", alias)
|
||||
gitRun(t, repo.work, "remote", "set-url", "origin", alias)
|
||||
|
||||
result, err := releasekit.Publish(context.Background(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repo.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
ExpectedPushURL: repo.bare,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Publish() with the resolved insteadOf destination failed: %v", err)
|
||||
}
|
||||
if result.Endpoint != repo.bare || result.State != releasekit.PublicationPublished {
|
||||
t.Fatalf("publication result = %#v, want resolved push URL and successful publication", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishExpectedPushURLUsesPushURLWhenFetchAndPushDiffer(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
fetchURL := filepath.Join(t.TempDir(), "fetch-only.git")
|
||||
gitRun(t, repo.work, "remote", "set-url", "origin", fetchURL)
|
||||
gitRun(t, repo.work, "config", "remote.origin.pushurl", repo.bare)
|
||||
|
||||
result, err := releasekit.Publish(context.Background(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repo.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
ExpectedPushURL: fetchURL,
|
||||
})
|
||||
if !errors.Is(err, releasekit.ErrUnexpectedPushURL) {
|
||||
t.Fatalf("Publish() error = %v, want ErrUnexpectedPushURL", err)
|
||||
}
|
||||
if result.Endpoint != repo.bare || !strings.Contains(err.Error(), fmt.Sprintf("resolved %q", repo.bare)) {
|
||||
t.Fatalf("result = %#v, error = %v; want the effective push URL %q", result, err, repo.bare)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckIgnoresExpectedPushURL(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
var callbacks int
|
||||
_, err := releasekit.Check(context.Background(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repo.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
ExpectedPushURL: "unrelated destination",
|
||||
AdditionalChecks: func(context.Context, releasekit.Candidate) error {
|
||||
callbacks++
|
||||
return nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Check() considered publication URL expectation: %v", err)
|
||||
}
|
||||
if callbacks != 1 {
|
||||
t.Fatalf("additional checks ran %d times, want one", callbacks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckUsesSelectedRaceSuiteBeforeAdditionalChecks(t *testing.T) {
|
||||
requireRacePrerequisites(t)
|
||||
repo := newPublishFixture(t)
|
||||
|
||||
Reference in New Issue
Block a user