package main import ( "bytes" "io" "strings" "testing" ) // `new` with a bad repo name (contains a slash) must fail before any network // call, keeping the test hermetic. func TestNewRejectsOwnerQualifiedRepo(t *testing.T) { cmd := newRootCmd() cmd.SetArgs([]string{"new", "unkin/argocd-apps", "--branch", "benvin/x"}) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) if err := cmd.Execute(); err == nil { t.Fatal("Execute() = nil, want error for owner-qualified repo name") } } // `new` without --branch must fail (cobra required-flag check) before any // network call. func TestNewRequiresBranch(t *testing.T) { cmd := newRootCmd() cmd.SetArgs([]string{"new", "argocd-apps"}) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) if err := cmd.Execute(); err == nil { t.Fatal("Execute() = nil, want error when --branch is missing") } } // An unknown credential action must fail. func TestCredentialUnknownAction(t *testing.T) { cmd := newRootCmd() cmd.SetArgs([]string{"credential", "bogus"}) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) if err := cmd.Execute(); err == nil { t.Fatal("Execute() = nil, want error for unknown credential action") } } // credentialGet must stay silent (and never mint a token) when git asks about a // host other than the configured Gitea host. This exercises the stdin parser // without any network access. func TestCredentialGetIgnoresOtherHost(t *testing.T) { in := strings.NewReader("protocol=https\nhost=github.com\n\n") var out bytes.Buffer if err := credentialGet(in, &out); err != nil { t.Fatalf("credentialGet: %v", err) } if out.Len() != 0 { t.Errorf("expected no output for non-Gitea host, got %q", out.String()) } } func TestGiteaHost(t *testing.T) { if h := giteaHost(); h != "git.unkin.net" { t.Errorf("giteaHost() = %q, want git.unkin.net", h) } }