@@ -220,6 +220,110 @@ func TestRepositoriesService_CreateEnvironment(t *testing.T) {
220220 })
221221}
222222
223+ func TestRepositoriesService_CreateEnvironment_noEnterprise (t * testing.T ) {
224+ client , mux , _ , teardown := setup ()
225+ defer teardown ()
226+
227+ input := & CreateUpdateEnvironment {}
228+ callCount := 0
229+
230+ mux .HandleFunc ("/repos/o/r/environments/e" , func (w http.ResponseWriter , r * http.Request ) {
231+ v := new (CreateUpdateEnvironment )
232+ json .NewDecoder (r .Body ).Decode (v )
233+
234+ testMethod (t , r , "PUT" )
235+ if callCount == 0 {
236+ w .WriteHeader (http .StatusUnprocessableEntity )
237+ callCount ++
238+ } else {
239+ want := & CreateUpdateEnvironment {}
240+ if ! cmp .Equal (v , want ) {
241+ t .Errorf ("Request body = %+v, want %+v" , v , want )
242+ }
243+ fmt .Fprint (w , `{"id": 1, "name": "staging", "protection_rules": []}` )
244+ }
245+ })
246+
247+ ctx := context .Background ()
248+ release , _ , err := client .Repositories .CreateUpdateEnvironment (ctx , "o" , "r" , "e" , input )
249+ if err != nil {
250+ t .Errorf ("Repositories.CreateUpdateEnvironment returned error: %v" , err )
251+ }
252+
253+ want := & Environment {ID : Int64 (1 ), Name : String ("staging" ), ProtectionRules : []* ProtectionRule {}}
254+ if ! cmp .Equal (release , want ) {
255+ t .Errorf ("Repositories.CreateUpdateEnvironment returned %+v, want %+v" , release , want )
256+ }
257+ }
258+
259+ func TestRepositoriesService_createNewEnvNoEnterprise (t * testing.T ) {
260+ client , mux , _ , teardown := setup ()
261+ defer teardown ()
262+
263+ input := & CreateUpdateEnvironment {
264+ DeploymentBranchPolicy : & BranchPolicy {
265+ ProtectedBranches : Bool (true ),
266+ CustomBranchPolicies : Bool (false ),
267+ },
268+ }
269+
270+ mux .HandleFunc ("/repos/o/r/environments/e" , func (w http.ResponseWriter , r * http.Request ) {
271+ v := new (createUpdateEnvironmentNoEnterprise )
272+ json .NewDecoder (r .Body ).Decode (v )
273+
274+ testMethod (t , r , "PUT" )
275+ want := & createUpdateEnvironmentNoEnterprise {
276+ DeploymentBranchPolicy : & BranchPolicy {
277+ ProtectedBranches : Bool (true ),
278+ CustomBranchPolicies : Bool (false ),
279+ },
280+ }
281+ if ! cmp .Equal (v , want ) {
282+ t .Errorf ("Request body = %+v, want %+v" , v , want )
283+ }
284+ fmt .Fprint (w , `{"id": 1, "name": "staging", "protection_rules": [{"id": 1, "node_id": "id", "type": "branch_policy"}], "deployment_branch_policy": {"protected_branches": true, "custom_branch_policies": false}}` )
285+ })
286+
287+ ctx := context .Background ()
288+ release , _ , err := client .Repositories .createNewEnvNoEnterprise (ctx , "repos/o/r/environments/e" , input )
289+ if err != nil {
290+ t .Errorf ("Repositories.createNewEnvNoEnterprise returned error: %v" , err )
291+ }
292+
293+ want := & Environment {
294+ ID : Int64 (1 ),
295+ Name : String ("staging" ),
296+ ProtectionRules : []* ProtectionRule {
297+ {
298+ ID : Int64 (1 ),
299+ NodeID : String ("id" ),
300+ Type : String ("branch_policy" ),
301+ },
302+ },
303+ DeploymentBranchPolicy : & BranchPolicy {
304+ ProtectedBranches : Bool (true ),
305+ CustomBranchPolicies : Bool (false ),
306+ },
307+ }
308+ if ! cmp .Equal (release , want ) {
309+ t .Errorf ("Repositories.createNewEnvNoEnterprise returned %+v, want %+v" , release , want )
310+ }
311+
312+ const methodName = "createNewEnvNoEnterprise"
313+ testBadOptions (t , methodName , func () (err error ) {
314+ _ , _ , err = client .Repositories .createNewEnvNoEnterprise (ctx , "\n " , input )
315+ return err
316+ })
317+
318+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
319+ got , resp , err := client .Repositories .createNewEnvNoEnterprise (ctx , "repos/o/r/environments/e" , input )
320+ if got != nil {
321+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
322+ }
323+ return resp , err
324+ })
325+ }
326+
223327func TestRepositoriesService_DeleteEnvironment (t * testing.T ) {
224328 client , mux , _ , teardown := setup ()
225329 defer teardown ()
0 commit comments