MCPcopy Index your code
hub / github.com/cli/cli / TestNewCmdClone

Function TestNewCmdClone

pkg/cmd/label/clone_test.go:16–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNewCmdClone(t *testing.T) {
17 tests := []struct {
18 name string
19 input string
20 output cloneOptions
21 wantErr bool
22 errMsg string
23 }{
24 {
25 name: "no argument",
26 input: "",
27 wantErr: true,
28 errMsg: "cannot clone labels: source-repository argument required",
29 },
30 {
31 name: "source-repository argument",
32 input: "OWNER/REPO",
33 output: cloneOptions{
34 SourceRepo: ghrepo.New("OWNER", "REPO"),
35 },
36 },
37 {
38 name: "force flag",
39 input: "OWNER/REPO --force",
40 output: cloneOptions{
41 SourceRepo: ghrepo.New("OWNER", "REPO"),
42 Force: true,
43 },
44 },
45 }
46
47 for _, tt := range tests {
48 t.Run(tt.name, func(t *testing.T) {
49 io, _, _, _ := iostreams.Test()
50 f := &cmdutil.Factory{
51 IOStreams: io,
52 }
53
54 var gotOpts *cloneOptions
55 cmd := newCmdClone(f, func(opts *cloneOptions) error {
56 gotOpts = opts
57 return nil
58 })
59
60 argv, err := shlex.Split(tt.input)
61 assert.NoError(t, err)
62
63 cmd.SetArgs(argv)
64 cmd.SetIn(&bytes.Buffer{})
65 cmd.SetOut(&bytes.Buffer{})
66 cmd.SetErr(&bytes.Buffer{})
67
68 _, err = cmd.ExecuteC()
69 if tt.wantErr {
70 assert.EqualError(t, err, tt.errMsg)
71 return
72 }
73

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
TestFunction · 0.92
newCmdCloneFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected