package app import ( "path/filepath" "strings" "testing" ) func TestCLICommandValidation(t *testing.T) { t.Setenv("GITOOCEAN_CONFIG", filepath.Join(t.TempDir(), "missing.json")) cases := []struct { name string fn func() error want string }{ {"repo missing", func() error { return cliRepo(nil) }, "usage"}, {"repo unknown", func() error { return cliRepo([]string{"wat"}) }, "unknown repo"}, {"repo create invalid", func() error { return cliRepoCreate([]string{"demo"}) }, "usage"}, {"repo publish invalid", func() error { return cliRepoPublish([]string{"demo", "--public", "--remote"}) }, "--remote requires"}, {"repo set invalid", func() error { return cliRepoSet([]string{"alice/demo"}) }, "no settings"}, {"repo archive invalid", func() error { return cliRepoArchive([]string{}, true) }, "usage"}, {"repo delete invalid", func() error { return cliRepoDelete([]string{}) }, "usage"}, {"repo search invalid", func() error { return cliRepoSearch([]string{"one", "two"}) }, "usage"}, {"repo fork invalid", func() error { return cliRepoFork([]string{}) }, "usage"}, {"repo collaborators invalid", func() error { return cliRepoCollaborators([]string{}) }, "usage"}, {"repo collaborator invalid", func() error { return cliRepoCollaborator([]string{"add"}) }, "usage"}, {"pr missing", func() error { return cliPR(nil) }, "usage"}, {"pr unknown", func() error { return cliPR([]string{"wat"}) }, "unknown pr"}, {"pr create invalid", func() error { return cliPRCreate(nil) }, "usage"}, {"pr diff invalid", func() error { return cliPRDiff([]string{"alice/demo"}) }, "usage"}, {"pr checkout invalid", func() error { return cliPRCheckout([]string{"alice/demo"}) }, "usage"}, {"pr comment invalid", func() error { return cliPRComment([]string{"alice/demo", "1"}) }, "usage"}, {"pr comments invalid", func() error { return cliPRComments([]string{"alice/demo"}) }, "usage"}, {"pr action invalid", func() error { return cliPRAction([]string{"alice/demo"}, "merge") }, "usage"}, {"token missing", func() error { return cliToken(nil) }, "usage"}, {"admin missing", func() error { return cliAdmin(nil) }, "usage"}, {"backup missing", func() error { return cliBackup(nil) }, "usage"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { err := tc.fn() if err == nil || !strings.Contains(err.Error(), tc.want) { t.Fatalf("error = %v, want containing %q", err, tc.want) } }) } } func TestRepoCloneURLAndWrapperHelpers(t *testing.T) { if got := repoCloneURL("http://server/", "alice", "demo"); got != "http://server/alice/demo.git" { t.Fatalf("repoCloneURL = %q", got) } if isReservedName("api") != true || isReservedName("alice") != false { t.Fatal("isReservedName wrapper mismatch") } if _, _, err := mysqlCLIArgs("bad dsn"); err == nil { t.Fatal("expected mysqlCLIArgs wrapper to fail on bad DSN") } if err := copyDir(filepath.Join(t.TempDir(), "missing"), filepath.Join(t.TempDir(), "dst")); err == nil { t.Fatal("expected copyDir wrapper to fail on missing source") } if _, err := gitRefs(filepath.Join(t.TempDir(), "missing.git"), "refs/heads"); err == nil { t.Fatal("expected gitRefs wrapper to fail on missing repo") } if gitBranchExists(filepath.Join(t.TempDir(), "missing.git"), "bad branch") { t.Fatal("invalid branch should not exist") } if err := runGit("", "definitely-not-a-git-command"); err == nil { t.Fatal("expected runGit wrapper to return git error") } }