(t *testing.T)
| 240 | } |
| 241 | |
| 242 | func 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) |
nothing calls this directly
no test coverage detected