Skip to content

Commit

Permalink
Add tests for deletion of branch restriction (#148)
Browse files Browse the repository at this point in the history
This has a the positive side effect of cleaning up after the creation tests (against a live Bitbucket account).
  • Loading branch information
oogali authored Jul 18, 2021
1 parent 4807eeb commit 23fc175
Showing 1 changed file with 63 additions and 30 deletions.
93 changes: 63 additions & 30 deletions tests/branchrestrictions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"os"
"strconv"
"testing"

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

func TestCreateBranchRestrictionsKindPush(t *testing.T) {
func TestBranchRestrictionsKindPush(t *testing.T) {

c := setup(t)
var pushRestrictionID int

opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
Pattern: "develop",
RepoSlug: repo,
Kind: "push",
Users: []string{user},
}
res, err := c.Repositories.BranchRestrictions.Create(opt)
if err != nil {
t.Error(err)
}
if res.Kind != "push" {
t.Error("did not match branchrestriction kind")
}
t.Run("create", func(t *testing.T) {
opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
Pattern: "develop",
RepoSlug: repo,
Kind: "push",
Users: []string{user},
}
res, err := c.Repositories.BranchRestrictions.Create(opt)
if err != nil {
t.Error(err)
}
if res.Kind != "push" {
t.Error("did not match branchrestriction kind")
}
pushRestrictionID = res.ID
})

t.Run("delete", func(t *testing.T) {
opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
RepoSlug: repo,
ID: strconv.Itoa(pushRestrictionID),
}
_, err := c.Repositories.BranchRestrictions.Delete(opt)
if err != nil {
t.Error(err)
}
})
}

func TestCreateBranchRestrictionsKindRequirePassingBuilds(t *testing.T) {
func TestBranchRestrictionsKindRequirePassingBuilds(t *testing.T) {

c := setup(t)
var pushRestrictionID int

opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
Pattern: "master",
RepoSlug: repo,
Kind: "require_passing_builds_to_merge",
Value: 2,
}
res, err := c.Repositories.BranchRestrictions.Create(opt)
if err != nil {
t.Error(err)
}
if res.Kind != "require_passing_builds_to_merge" {
t.Error("did not match branchrestriction kind")
}
t.Run("create", func(t *testing.T) {
opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
Pattern: "master",
RepoSlug: repo,
Kind: "require_passing_builds_to_merge",
Value: 2,
}
res, err := c.Repositories.BranchRestrictions.Create(opt)
if err != nil {
t.Error(err)
}
if res.Kind != "require_passing_builds_to_merge" {
t.Error("did not match branchrestriction kind")
}
pushRestrictionID = res.ID
})

t.Run("delete", func(t *testing.T) {
opt := &bitbucket.BranchRestrictionsOptions{
Owner: owner,
RepoSlug: repo,
ID: strconv.Itoa(pushRestrictionID),
}
_, err := c.Repositories.BranchRestrictions.Delete(opt)
if err != nil {
t.Error(err)
}
})
}

0 comments on commit 23fc175

Please sign in to comment.