Stop recovery when endpoint resolution changes
This commit is contained in:
@@ -17,6 +17,7 @@ func TestReleaseWrapperPreservesNativeExitStatuses(t *testing.T) {
|
||||
}
|
||||
_, source, _, _ := runtime.Caller(0)
|
||||
root := filepath.Clean(filepath.Join(filepath.Dir(source), "../.."))
|
||||
originalPath := os.Getenv("PATH")
|
||||
realGit, err := exec.LookPath("git")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -119,15 +120,28 @@ exec "$RELEASEKIT_TEST_REAL_GIT" "$@"
|
||||
if !strings.Contains(string(output), fmt.Sprintf("endpoint=%q", remote)) {
|
||||
t.Fatalf("captured endpoint missing: %s", output)
|
||||
}
|
||||
query := exec.Command(realGit, "ls-remote", "--refs", "--", remote, "refs/tags/v1.2.3")
|
||||
t.Setenv("PATH", originalPath)
|
||||
// Execute the runbook's guarded recovery commands verbatim.
|
||||
recovery := `test "$(git ls-remote --get-url -- "$releasekit_endpoint")" = "$releasekit_endpoint" &&
|
||||
git ls-remote --refs -- "$releasekit_endpoint" "refs/tags/$releasekit_version"`
|
||||
query := exec.Command("sh", "-c", recovery)
|
||||
query.Dir = repository
|
||||
query.Env = append(os.Environ(), "releasekit_endpoint="+remote, "releasekit_version=v1.2.3")
|
||||
found, err := query.Output()
|
||||
if err != nil || len(found) == 0 {
|
||||
t.Fatalf("captured endpoint lost published tag: %q %v", found, err)
|
||||
t.Fatalf("captured endpoint recovery failed: %q %v", found, err)
|
||||
}
|
||||
if !strings.Contains(string(found), cliGitOutput(t, repository, "rev-parse", "refs/tags/v1.2.3")) {
|
||||
t.Fatalf("wrong recovered tag: %s", found)
|
||||
}
|
||||
cliGitRun(t, repository, "config", "url."+fetch+".insteadOf", remote)
|
||||
blocked := exec.Command("sh", "-c", recovery)
|
||||
blocked.Dir = repository
|
||||
blocked.Env = query.Env
|
||||
if output, err := blocked.Output(); err == nil || len(output) != 0 {
|
||||
t.Fatalf("rewritten endpoint should block query: %q %v", output, err)
|
||||
}
|
||||
|
||||
fetchQuery := exec.Command(realGit, "ls-remote", "--refs", "origin", "refs/tags/v1.2.3")
|
||||
fetchQuery.Dir = repository
|
||||
stale, err := fetchQuery.Output()
|
||||
|
||||
Reference in New Issue
Block a user