package main import ( "io" "strings" "testing" ) // A malformed --repo must fail the command (so main exits non-zero). ParseRepo // rejects it before any Vault/Gitea call, so this stays hermetic. func TestExecuteBadRepoErrors(t *testing.T) { cmd := newRootCmd() cmd.SetArgs([]string{"pr", "create", "--repo", "not-a-repo", "--base", "main", "--head", "x", "--title", "t"}) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) if err := cmd.Execute(); err == nil { t.Fatal("Execute() = nil, want error for a malformed --repo") } } // `pr edit` with neither --title nor --body has nothing to send; it must fail // with a usage error before any Vault/Gitea call, so this stays hermetic. func TestPREditRequiresTitleOrBody(t *testing.T) { cmd := newRootCmd() cmd.SetArgs([]string{"pr", "edit", "--repo", "unkin/repo", "--pr", "7"}) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) err := cmd.Execute() if err == nil { t.Fatal("Execute() = nil, want an error when neither --title nor --body is given") } if !strings.Contains(err.Error(), "--title or --body") { t.Errorf("error = %q, want it to name the missing flags", err) } }