MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdSetDefault

Function TestNewCmdSetDefault

pkg/cmd/repo/setdefault/setdefault_test.go:20–176  ·  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 nonTTY bool
28 wantErr bool
29 errMsg string
30 }{
31 {
32 name: "no argument",
33 gitStubs: func(cs *run.CommandStubber) {
34 cs.Register(`git rev-parse --git-dir`, 0, ".git")
35 },
36 input: "",
37 output: SetDefaultOptions{},
38 },
39 {
40 name: "repo argument",
41 gitStubs: func(cs *run.CommandStubber) {
42 cs.Register(`git rev-parse --git-dir`, 0, ".git")
43 },
44 input: "cli/cli",
45 output: SetDefaultOptions{Repo: ghrepo.New("cli", "cli")},
46 },
47 {
48 name: "invalid repo argument",
49 gitStubs: func(cs *run.CommandStubber) {
50 cs.Register(`git rev-parse --git-dir`, 0, ".git")
51 },
52 input: "some_invalid_format",
53 wantErr: true,
54 errMsg: `given arg is not a valid repo or git remote: expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"`,
55 },
56 {
57 name: "view flag",
58 gitStubs: func(cs *run.CommandStubber) {
59 cs.Register(`git rev-parse --git-dir`, 0, ".git")
60 },
61 input: "--view",
62 output: SetDefaultOptions{ViewMode: true},
63 nonTTY: true,
64 },
65 {
66 name: "unset flag",
67 gitStubs: func(cs *run.CommandStubber) {
68 cs.Register(`git rev-parse --git-dir`, 0, ".git")
69 },
70 input: "--unset",
71 output: SetDefaultOptions{UnsetMode: true},
72 nonTTY: true,
73 },
74 {
75 name: "no argument when not running interactively",
76 gitStubs: func(cs *run.CommandStubber) {
77 cs.Register(`git rev-parse --git-dir`, 0, ".git")

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