MCPcopy
hub / github.com/cli/cli / Test_setRun_env

Function Test_setRun_env

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

Source from the content-addressed store, hash-verified

240}
241
242func Test_setRun_env(t *testing.T) {
243 tests := []struct {
244 name string
245 opts *SetOptions
246 httpStubs func(*httpmock.Registry)
247 wantErr bool
248 }{
249 {
250 name: "create env variable",
251 opts: &SetOptions{},
252 httpStubs: func(reg *httpmock.Registry) {
253 reg.Register(httpmock.GraphQL(`query MapRepositoryNames\b`),
254 httpmock.StringResponse(`{"data":{"repo_0001":{"databaseId":1}}}`))
255 reg.Register(httpmock.REST("POST", "repositories/1/environments/release/variables"),
256 httpmock.StatusStringResponse(201, `{}`))
257 },
258 },
259 {
260 name: "update env variable",
261 opts: &SetOptions{},
262 httpStubs: func(reg *httpmock.Registry) {
263 reg.Register(httpmock.GraphQL(`query MapRepositoryNames\b`),
264 httpmock.StringResponse(`{"data":{"repo_0001":{"databaseId":1}}}`))
265 reg.Register(httpmock.REST("POST", "repositories/1/environments/release/variables"),
266 httpmock.StatusStringResponse(409, `{}`))
267 reg.Register(httpmock.REST("PATCH", "repositories/1/environments/release/variables/cool_variable"),
268 httpmock.StatusStringResponse(204, `{}`))
269 },
270 },
271 }
272
273 for _, tt := range tests {
274 t.Run(tt.name, func(t *testing.T) {
275 reg := &httpmock.Registry{}
276 defer reg.Verify(t)
277 if tt.httpStubs != nil {
278 tt.httpStubs(reg)
279 }
280
281 ios, _, _, _ := iostreams.Test()
282
283 opts := &SetOptions{
284 HttpClient: func() (*http.Client, error) {
285 return &http.Client{Transport: reg}, nil
286 },
287 Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil },
288 BaseRepo: func() (ghrepo.Interface, error) {
289 return ghrepo.FromFullName("owner/repo")
290 },
291 IO: ios,
292 VariableName: "cool_variable",
293 Body: "a variable",
294 EnvName: "release",
295 }
296
297 err := setRun(opts)
298 if tt.wantErr {
299 assert.Error(t, err)

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected