MCPcopy
hub / github.com/cli/cli / TestDeleteRun

Function TestDeleteRun

pkg/cmd/label/delete_test.go:84–182  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestDeleteRun(t *testing.T) {
85 tests := []struct {
86 name string
87 tty bool
88 opts *deleteOptions
89 httpStubs func(*httpmock.Registry)
90 prompterStubs func(*prompter.PrompterMock)
91 wantStdout string
92 wantErr bool
93 errMsg string
94 }{
95 {
96 name: "deletes label",
97 tty: true,
98 opts: &deleteOptions{Name: "test"},
99 httpStubs: func(reg *httpmock.Registry) {
100 reg.Register(
101 httpmock.REST("DELETE", "repos/OWNER/REPO/labels/test"),
102 httpmock.StatusStringResponse(204, "{}"),
103 )
104 },
105 prompterStubs: func(pm *prompter.PrompterMock) {
106 pm.ConfirmDeletionFunc = func(_ string) error {
107 return nil
108 }
109 },
110 wantStdout: "✓ Label \"test\" deleted from OWNER/REPO\n",
111 },
112 {
113 name: "deletes label notty",
114 tty: false,
115 opts: &deleteOptions{Name: "test", Confirmed: true},
116 httpStubs: func(reg *httpmock.Registry) {
117 reg.Register(
118 httpmock.REST("DELETE", "repos/OWNER/REPO/labels/test"),
119 httpmock.StatusStringResponse(204, "{}"),
120 )
121 },
122 wantStdout: "",
123 },
124 {
125 name: "missing label",
126 tty: false,
127 opts: &deleteOptions{Name: "missing", Confirmed: true},
128 httpStubs: func(reg *httpmock.Registry) {
129 reg.Register(
130 httpmock.REST("DELETE", "repos/OWNER/REPO/labels/missing"),
131 httpmock.WithHeader(
132 httpmock.StatusStringResponse(422, `
133 {
134 "message":"Not Found"
135 }`),
136 "Content-Type",
137 "application/json",
138 ),
139 )
140 },
141 wantErr: true,

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
WithHeaderFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
deleteRunFunction · 0.70

Tested by

no test coverage detected