Files
unkin-agent d78644d173
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/pr/pre-commit Pipeline failed
Add agentpr and watchpr CLI tools
agentpr manages PRs/comments/whoami as unkin-agent (Vault AppRole -> gitea creds
-> Gitea API), fixing tea's post-as-Ben default. watchpr polls PRs and alerts
only on merge/close, human comment, CI failure, or lost mergeability.

- cobra multi-binary layout mirroring node-lookup (cmd/ + internal/)
- Makefile (build, patch|minor|major, completions, rpm), nfpm RPM with both
  binaries + bash/zsh/fish completions, woodpecker CI publishing to rpm-internal
- unit tests for parsing, meaningful-change detection, and the Vault+Gitea client
2026-08-12 21:37:09 +10:00

80 lines
2.0 KiB
Go

package agent
import "testing"
func TestParsePRRef(t *testing.T) {
tests := []struct {
in string
wantErr bool
owner string
repo string
num int
}{
{"unkin/argocd-apps#42", false, "unkin", "argocd-apps", 42},
{"unkin/argocd-apps:42", false, "unkin", "argocd-apps", 42},
{" unkin/repo#1 ", false, "unkin", "repo", 1},
{"unkin/repo#0", true, "", "", 0},
{"unkin/repo#-3", true, "", "", 0},
{"unkin/repo#abc", true, "", "", 0},
{"unkin/repo", true, "", "", 0},
{"unkinrepo#3", true, "", "", 0},
{"unkin/a/b#3", true, "", "", 0},
{"/repo#3", true, "", "", 0},
{"unkin/#3", true, "", "", 0},
}
for _, tt := range tests {
got, err := ParsePRRef(tt.in)
if tt.wantErr {
if err == nil {
t.Errorf("ParsePRRef(%q): expected error, got %+v", tt.in, got)
}
continue
}
if err != nil {
t.Errorf("ParsePRRef(%q): unexpected error: %v", tt.in, err)
continue
}
if got.Owner != tt.owner || got.Repo != tt.repo || got.Number != tt.num {
t.Errorf("ParsePRRef(%q) = %+v, want %s/%s#%d", tt.in, got, tt.owner, tt.repo, tt.num)
}
}
}
func TestPRRefString(t *testing.T) {
r := PRRef{Owner: "unkin", Repo: "repo", Number: 7}
if got := r.String(); got != "unkin/repo#7" {
t.Errorf("String() = %q, want unkin/repo#7", got)
}
if got := r.RepoPath(); got != "unkin/repo" {
t.Errorf("RepoPath() = %q, want unkin/repo", got)
}
}
func TestParseRepo(t *testing.T) {
tests := []struct {
in string
wantErr bool
owner string
repo string
}{
{"unkin/repo", false, "unkin", "repo"},
{" unkin/repo ", false, "unkin", "repo"},
{"repo", true, "", ""},
{"unkin/a/b", true, "", ""},
{"/repo", true, "", ""},
{"unkin/", true, "", ""},
}
for _, tt := range tests {
o, r, err := ParseRepo(tt.in)
if tt.wantErr {
if err == nil {
t.Errorf("ParseRepo(%q): expected error", tt.in)
}
continue
}
if err != nil || o != tt.owner || r != tt.repo {
t.Errorf("ParseRepo(%q) = (%q,%q,%v), want (%q,%q,nil)", tt.in, o, r, err, tt.owner, tt.repo)
}
}
}