MCPcopy
hub / github.com/cli/cli / Test_setRun_repo

Function Test_setRun_repo

pkg/cmd/variable/set/set_test.go:176–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func Test_setRun_repo(t *testing.T) {
177 tests := []struct {
178 name string
179 httpStubs func(*httpmock.Registry)
180 wantErr bool
181 }{
182 {
183 name: "create actions variable",
184 httpStubs: func(reg *httpmock.Registry) {
185 reg.Register(httpmock.REST("POST", "repos/owner/repo/actions/variables"),
186 httpmock.StatusStringResponse(201, `{}`))
187 },
188 },
189 {
190 name: "update actions variable",
191 httpStubs: func(reg *httpmock.Registry) {
192 reg.Register(httpmock.REST("POST", "repos/owner/repo/actions/variables"),
193 httpmock.StatusStringResponse(409, `{}`))
194 reg.Register(httpmock.REST("PATCH", "repos/owner/repo/actions/variables/cool_variable"),
195 httpmock.StatusStringResponse(204, `{}`))
196 },
197 },
198 }
199
200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
202 reg := &httpmock.Registry{}
203 defer reg.Verify(t)
204 if tt.httpStubs != nil {
205 tt.httpStubs(reg)
206 }
207
208 ios, _, _, _ := iostreams.Test()
209
210 opts := &SetOptions{
211 HttpClient: func() (*http.Client, error) {
212 return &http.Client{Transport: reg}, nil
213 },
214 Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil },
215 BaseRepo: func() (ghrepo.Interface, error) {
216 return ghrepo.FromFullName("owner/repo")
217 },
218 IO: ios,
219 VariableName: "cool_variable",
220 Body: "a variable",
221 }
222
223 err := setRun(opts)
224 if tt.wantErr {
225 assert.Error(t, err)
226 return
227 } else {
228 assert.NoError(t, err)
229 }
230
231 data, err := io.ReadAll(reg.Requests[len(reg.Requests)-1].Body)
232 assert.NoError(t, err)
233

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
FromFullNameFunction · 0.92
EqualMethod · 0.80
setRunFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected