Present validation errors consistently in the CLI
This commit is contained in:
@@ -97,6 +97,58 @@ func TestCheckCommandBindsConfiguredChecksToCapturedCandidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCandidateCommandsPresentValidationDiagnosticsOnce(t *testing.T) {
|
||||
repository := newCLIRepository(t)
|
||||
profile, err := json.Marshal(cli.Settings{Product: "Example Product"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeRepositoryFile(t, repository, "releasekit.json", string(profile))
|
||||
cliGitRun(t, repository, "add", "releasekit.json")
|
||||
cliGitRun(t, repository, "commit", "-m", "configure candidate commands")
|
||||
remote := filepath.Join(t.TempDir(), "origin.git")
|
||||
cliGitRun(t, repository, "init", "--bare", remote)
|
||||
cliGitRun(t, repository, "remote", "add", "origin", remote)
|
||||
cliGitRun(t, repository, "push", "origin", "HEAD:refs/heads/main")
|
||||
|
||||
goPath, err := exec.LookPath("go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
goDirectory := t.TempDir()
|
||||
shim := filepath.Join(goDirectory, "go")
|
||||
if err := os.WriteFile(shim, []byte("#!/bin/sh\nif [ \"$1\" = test ]; then echo 'fixture Go suite failure' >&2; exit 1; fi\nexec \"$RELEASEKIT_REAL_GO\" \"$@\"\n"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("RELEASEKIT_REAL_GO", goPath)
|
||||
t.Setenv("PATH", goDirectory+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
|
||||
for _, command := range []struct {
|
||||
name string
|
||||
wantStatus int
|
||||
args []string
|
||||
}{
|
||||
{name: "check", wantStatus: 1, args: []string{"check", "--repo", repository, "v1.2.3"}},
|
||||
{name: "publish", wantStatus: 1, args: []string{"publish", "--repo", repository, "v1.2.3"}},
|
||||
} {
|
||||
t.Run(command.name, func(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
if status := run(context.Background(), command.args, &stdout, &stderr); status != command.wantStatus {
|
||||
t.Fatalf("run() status = %d; stdout=%q stderr=%q", status, stdout.String(), stderr.String())
|
||||
}
|
||||
if got := strings.Count(stderr.String(), "go-test validation failed"); got != 1 {
|
||||
t.Fatalf("validation diagnostic appeared %d times: %q", got, stderr.String())
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "fixture Go suite failure") {
|
||||
t.Fatalf("stderr omitted the validation cause: %q", stderr.String())
|
||||
}
|
||||
if command.name == "publish" && !strings.Contains(stderr.String(), "state=not_attempted phase=validation") {
|
||||
t.Fatalf("publication validation error lost its state: %q", stderr.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishCommandPublishesConfiguredCandidate(t *testing.T) {
|
||||
repository := newCLIRepository(t)
|
||||
writeRepositoryFile(t, repository, "docs/releases/v1.2.3.md", "# Example Product v1.2.3\n\n## Compatibility\n\nNo action required.\n")
|
||||
|
||||
Reference in New Issue
Block a user