Skip to content

Commit 23fc175

Browse files
authored
Add tests for deletion of branch restriction (#148)
This has a the positive side effect of cleaning up after the creation tests (against a live Bitbucket account).
1 parent 4807eeb commit 23fc175

File tree

1 file changed

+63
-30
lines changed

1 file changed

+63
-30
lines changed

tests/branchrestrictions_test.go

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"os"
5+
"strconv"
56
"testing"
67

78
"github.com/ktrysmt/go-bitbucket"
@@ -33,42 +34,74 @@ func setup(t *testing.T) *bitbucket.Client {
3334
return c
3435
}
3536

36-
func TestCreateBranchRestrictionsKindPush(t *testing.T) {
37+
func TestBranchRestrictionsKindPush(t *testing.T) {
3738

3839
c := setup(t)
40+
var pushRestrictionID int
3941

40-
opt := &bitbucket.BranchRestrictionsOptions{
41-
Owner: owner,
42-
Pattern: "develop",
43-
RepoSlug: repo,
44-
Kind: "push",
45-
Users: []string{user},
46-
}
47-
res, err := c.Repositories.BranchRestrictions.Create(opt)
48-
if err != nil {
49-
t.Error(err)
50-
}
51-
if res.Kind != "push" {
52-
t.Error("did not match branchrestriction kind")
53-
}
42+
t.Run("create", func(t *testing.T) {
43+
opt := &bitbucket.BranchRestrictionsOptions{
44+
Owner: owner,
45+
Pattern: "develop",
46+
RepoSlug: repo,
47+
Kind: "push",
48+
Users: []string{user},
49+
}
50+
res, err := c.Repositories.BranchRestrictions.Create(opt)
51+
if err != nil {
52+
t.Error(err)
53+
}
54+
if res.Kind != "push" {
55+
t.Error("did not match branchrestriction kind")
56+
}
57+
pushRestrictionID = res.ID
58+
})
59+
60+
t.Run("delete", func(t *testing.T) {
61+
opt := &bitbucket.BranchRestrictionsOptions{
62+
Owner: owner,
63+
RepoSlug: repo,
64+
ID: strconv.Itoa(pushRestrictionID),
65+
}
66+
_, err := c.Repositories.BranchRestrictions.Delete(opt)
67+
if err != nil {
68+
t.Error(err)
69+
}
70+
})
5471
}
5572

56-
func TestCreateBranchRestrictionsKindRequirePassingBuilds(t *testing.T) {
73+
func TestBranchRestrictionsKindRequirePassingBuilds(t *testing.T) {
5774

5875
c := setup(t)
76+
var pushRestrictionID int
5977

60-
opt := &bitbucket.BranchRestrictionsOptions{
61-
Owner: owner,
62-
Pattern: "master",
63-
RepoSlug: repo,
64-
Kind: "require_passing_builds_to_merge",
65-
Value: 2,
66-
}
67-
res, err := c.Repositories.BranchRestrictions.Create(opt)
68-
if err != nil {
69-
t.Error(err)
70-
}
71-
if res.Kind != "require_passing_builds_to_merge" {
72-
t.Error("did not match branchrestriction kind")
73-
}
78+
t.Run("create", func(t *testing.T) {
79+
opt := &bitbucket.BranchRestrictionsOptions{
80+
Owner: owner,
81+
Pattern: "master",
82+
RepoSlug: repo,
83+
Kind: "require_passing_builds_to_merge",
84+
Value: 2,
85+
}
86+
res, err := c.Repositories.BranchRestrictions.Create(opt)
87+
if err != nil {
88+
t.Error(err)
89+
}
90+
if res.Kind != "require_passing_builds_to_merge" {
91+
t.Error("did not match branchrestriction kind")
92+
}
93+
pushRestrictionID = res.ID
94+
})
95+
96+
t.Run("delete", func(t *testing.T) {
97+
opt := &bitbucket.BranchRestrictionsOptions{
98+
Owner: owner,
99+
RepoSlug: repo,
100+
ID: strconv.Itoa(pushRestrictionID),
101+
}
102+
_, err := c.Repositories.BranchRestrictions.Delete(opt)
103+
if err != nil {
104+
t.Error(err)
105+
}
106+
})
74107
}

0 commit comments

Comments
 (0)