MCPcopy
hub / github.com/cli/cli / TestNewCmdSetDefault

Function TestNewCmdSetDefault

pkg/cmd/repo/setdefault/setdefault_test.go:20–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestNewCmdSetDefault(t *testing.T) {
21 tests := []struct {
22 name string
23 gitStubs func(*run.CommandStubber)
24 remotes func() (context.Remotes, error)
25 input string
26 output SetDefaultOptions
27 wantErr bool
28 errMsg string
29 }{
30 {
31 name: "no argument",
32 gitStubs: func(cs *run.CommandStubber) {
33 cs.Register(`git rev-parse --git-dir`, 0, ".git")
34 },
35 input: "",
36 output: SetDefaultOptions{},
37 },
38 {
39 name: "repo argument",
40 gitStubs: func(cs *run.CommandStubber) {
41 cs.Register(`git rev-parse --git-dir`, 0, ".git")
42 },
43 input: "cli/cli",
44 output: SetDefaultOptions{Repo: ghrepo.New("cli", "cli")},
45 },
46 {
47 name: "invalid repo argument",
48 gitStubs: func(cs *run.CommandStubber) {
49 cs.Register(`git rev-parse --git-dir`, 0, ".git")
50 },
51 input: "some_invalid_format",
52 wantErr: true,
53 errMsg: `given arg is not a valid repo or git remote: expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"`,
54 },
55 {
56 name: "view flag",
57 gitStubs: func(cs *run.CommandStubber) {
58 cs.Register(`git rev-parse --git-dir`, 0, ".git")
59 },
60 input: "--view",
61 output: SetDefaultOptions{ViewMode: true},
62 },
63 {
64 name: "unset flag",
65 gitStubs: func(cs *run.CommandStubber) {
66 cs.Register(`git rev-parse --git-dir`, 0, ".git")
67 },
68 input: "--unset",
69 output: SetDefaultOptions{UnsetMode: true},
70 },
71 {
72 name: "run from non-git directory",
73 gitStubs: func(cs *run.CommandStubber) {
74 cs.Register(`git rev-parse --git-dir`, 128, "")
75 },
76 input: "",
77 wantErr: true,

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
TestFunction · 0.92
StubFunction · 0.92
NewCmdSetDefaultFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected