MCPcopy
hub / github.com/cli/cli / TestNewCmdUnarchive

Function TestNewCmdUnarchive

pkg/cmd/repo/unarchive/unarchive_test.go:18–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestNewCmdUnarchive(t *testing.T) {
19 tests := []struct {
20 name string
21 input string
22 wantErr bool
23 output UnarchiveOptions
24 errMsg string
25 }{
26 {
27 name: "no arguments no tty",
28 input: "",
29 errMsg: "--yes required when not running interactively",
30 wantErr: true,
31 },
32 {
33 name: "repo argument tty",
34 input: "OWNER/REPO --confirm",
35 output: UnarchiveOptions{RepoArg: "OWNER/REPO", Confirmed: true},
36 },
37 }
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 ios, _, _, _ := iostreams.Test()
41 f := &cmdutil.Factory{
42 IOStreams: ios,
43 }
44 argv, err := shlex.Split(tt.input)
45 assert.NoError(t, err)
46 var gotOpts *UnarchiveOptions
47 cmd := NewCmdUnarchive(f, func(opts *UnarchiveOptions) error {
48 gotOpts = opts
49 return nil
50 })
51 cmd.SetArgs(argv)
52 cmd.SetIn(&bytes.Buffer{})
53 cmd.SetOut(&bytes.Buffer{})
54 cmd.SetErr(&bytes.Buffer{})
55
56 _, err = cmd.ExecuteC()
57 if tt.wantErr {
58 assert.Error(t, err)
59 return
60 }
61 assert.NoError(t, err)
62 assert.Equal(t, tt.output.RepoArg, gotOpts.RepoArg)
63 assert.Equal(t, tt.output.Confirmed, gotOpts.Confirmed)
64 })
65 }
66}
67
68func Test_UnarchiveRun(t *testing.T) {
69 queryResponse := `{ "data": { "repository": { "id": "THE-ID","isArchived": %s} } }`

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
NewCmdUnarchiveFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected