Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}