Skip to content

Commit

Permalink
GH-73 Replace IF-style test assertion remnants with stretchr/testify (
Browse files Browse the repository at this point in the history
  • Loading branch information
zahiar authored Feb 15, 2022
1 parent 6bb1122 commit 6b19517
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 128 deletions.
53 changes: 16 additions & 37 deletions bitbucket/api/v1/group_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package v1
import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGroupMembers(t *testing.T) {
Expand All @@ -24,12 +26,10 @@ func TestGroupMembers(t *testing.T) {
Name: "tf-bb-group-members-test",
},
)
if group == nil {
t.Error("The Group could not be created.")
}
assert.NotNil(t, group, "The Group could not be created")
})

t.Run("Create", func(t *testing.T) {
t.Run("create", func(t *testing.T) {
result, err := c.GroupMembers.Create(
&GroupMemberOptions{
OwnerUuid: c.Auth.Username,
Expand All @@ -38,61 +38,42 @@ func TestGroupMembers(t *testing.T) {
},
)

if err != nil {
t.Error(err)
}

if result == nil {
t.Error("Expected result")
} else if result.UUID != group.Owner.Uuid {
t.Error("The GroupMember list contains an unexpected member.")
}
assert.NoError(t, err)
assert.NotNil(t, result)
assert.Equal(t, group.Owner.Uuid, result.UUID, "The GroupMember list contains an unexpected member")
})

t.Run("Get", func(t *testing.T) {
t.Run("get", func(t *testing.T) {
members, err := c.GroupMembers.Get(
&GroupMemberOptions{
OwnerUuid: c.Auth.Username,
Slug: group.Slug,
},
)
if err != nil {
t.Error(err)
}

if len(members) != 1 {
t.Error("The GroupMember list contains unexpected members.")
}
if members[0].UUID != group.Owner.Uuid {
t.Error("The GroupMember list contains an unexpected member.")
}
assert.NoError(t, err)
assert.Equal(t, 1, len(members), "The GroupMember list contains unexpected members")
assert.Equal(t, group.Owner.Uuid, members[0].UUID, "The GroupMember list contains an unexpected member")
})

t.Run("Delete", func(t *testing.T) {
t.Run("delete", func(t *testing.T) {
err := c.GroupMembers.Delete(
&GroupMemberOptions{
OwnerUuid: c.Auth.Username,
Slug: group.Slug,
UserUuid: group.Owner.Uuid,
},
)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)

members, err := c.GroupMembers.Get(
&GroupMemberOptions{
OwnerUuid: c.Auth.Username,
Slug: group.Slug,
},
)
if err != nil {
t.Error(err)
}

if len(members) != 0 {
t.Error("The GroupMember list contains unexpected members after deleting the member.")
}
assert.NoError(t, err)
assert.Equal(t, 0, len(members), "The GroupMember list contains unexpected members after deleting the member")
})

t.Run("teardown", func(t *testing.T) {
Expand All @@ -101,8 +82,6 @@ func TestGroupMembers(t *testing.T) {
Slug: group.Slug,
}
err := c.Groups.Delete(opt)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
})
}
65 changes: 19 additions & 46 deletions bitbucket/api/v1/group_privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

gobb "github.com/ktrysmt/go-bitbucket"
"github.com/stretchr/testify/assert"
)

func TestGroupPrivileges(t *testing.T) {
Expand Down Expand Up @@ -33,9 +34,7 @@ func TestGroupPrivileges(t *testing.T) {
Name: "tf-bb-group-test",
},
)
if group == nil {
t.Error("The Group could not be created.")
}
assert.NotNil(t, group)

project, _ = gobbClient.Workspaces.CreateProject(
&gobb.ProjectOptions{
Expand All @@ -45,9 +44,7 @@ func TestGroupPrivileges(t *testing.T) {
IsPrivate: true,
},
)
if project == nil {
t.Error("The Project could not be created.")
}
assert.NotNil(t, project)

repo, _ = gobbClient.Repositories.Repository.Create(
&gobb.RepositoryOptions{
Expand All @@ -58,9 +55,7 @@ func TestGroupPrivileges(t *testing.T) {
IsPrivate: "true",
},
)
if repo == nil {
t.Error("The Repository could not be created.")
}
assert.NotNil(t, repo)
})

t.Run("create", func(t *testing.T) {
Expand All @@ -72,19 +67,11 @@ func TestGroupPrivileges(t *testing.T) {
Privilege: "write",
}
groupPrivilege, err := c.GroupPrivileges.Create(opt)
if err != nil {
t.Error(err)
}

if groupPrivilege.Privilege != "write" {
t.Error("The Group Privilege `privilege` attribute does not match the expected value.")
}
if groupPrivilege.Group.Slug != group.Slug {
t.Error("The Group Privilege `group.slug` attribute does not match the expected value.")
}
if groupPrivilege.Repository.Slug != repo.Slug {
t.Error("The Group Privilege `repo.slug` attribute does not match the expected value.")
}
assert.NoError(t, err)
assert.Equal(t, "write", groupPrivilege.Privilege)
assert.Equal(t, group.Slug, groupPrivilege.Group.Slug)
assert.Equal(t, repo.Slug, groupPrivilege.Repository.Slug)
})

t.Run("get", func(t *testing.T) {
Expand All @@ -95,19 +82,11 @@ func TestGroupPrivileges(t *testing.T) {
GroupSlug: group.Slug,
}
groupPrivilege, err := c.GroupPrivileges.Get(opt)
if err != nil {
t.Error(err)
}

if groupPrivilege.Privilege != "write" {
t.Error("The Group Privilege `privilege` attribute does not match the expected value.")
}
if groupPrivilege.Group.Slug != group.Slug {
t.Error("The Group Privilege `group.slug` attribute does not match the expected value.")
}
if groupPrivilege.Repository.Slug != repo.Slug {
t.Error("The Group Privilege `repo.slug` attribute does not match the expected value.")
}
assert.NoError(t, err)
assert.Equal(t, "write", groupPrivilege.Privilege)
assert.Equal(t, group.Slug, groupPrivilege.Group.Slug)
assert.Equal(t, repo.Slug, groupPrivilege.Repository.Slug)
})

t.Run("delete", func(t *testing.T) {
Expand All @@ -119,19 +98,17 @@ func TestGroupPrivileges(t *testing.T) {
GroupSlug: group.Slug,
},
)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
})

err = c.Groups.Delete(
t.Run("teardown", func(t *testing.T) {
err := c.Groups.Delete(
&GroupOptions{
OwnerUuid: c.Auth.Username,
Slug: group.Slug,
},
)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)

_, err = gobbClient.Repositories.Repository.Delete(
&gobb.RepositoryOptions{
Expand All @@ -140,9 +117,7 @@ func TestGroupPrivileges(t *testing.T) {
Project: project.Key,
},
)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)

_, err = gobbClient.Workspaces.DeleteProject(
&gobb.ProjectOptions{
Expand All @@ -151,8 +126,6 @@ func TestGroupPrivileges(t *testing.T) {
Key: project.Key,
},
)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
})
}
60 changes: 15 additions & 45 deletions bitbucket/api/v1/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ func TestGroups(t *testing.T) {
}

group, err := c.Groups.Create(opt)
if err != nil {
t.Error(err)
}

if group.Name != name {
t.Error("The Group `name` attribute does not match the expected value.")
}
if group.AutoAdd != false {
t.Error("The Group `auto_add` attribute does not match the expected value.")
}
if group.Permission != "" {
t.Error("The Group `permission` attribute does not match the expected value.")
}
assert.NoError(t, err)
assert.Equal(t, name, group.Name)
assert.False(t, group.AutoAdd)
assert.Empty(t, group.Permission)

groupResourceSlug = group.Slug
})
Expand All @@ -51,22 +43,12 @@ func TestGroups(t *testing.T) {
Slug: groupResourceSlug,
}
group, err := c.Groups.Get(opt)
if err != nil {
t.Error(err)
}

if group.Name != name {
t.Error("The Group `name` attribute does not match the expected value.")
}
if group.AutoAdd != false {
t.Error("The Group `auto_add` attribute does not match the expected value.")
}
if group.Permission != "" {
t.Error("The Group `permission` attribute does not match the expected value.")
}
if group.Slug != groupResourceSlug {
t.Error("The Group `slug` attribute does not match the expected value.")
}
assert.NoError(t, err)
assert.Equal(t, name, group.Name)
assert.False(t, group.AutoAdd)
assert.Empty(t, group.Permission)
assert.Equal(t, groupResourceSlug, group.Slug)
})

t.Run("update", func(t *testing.T) {
Expand All @@ -77,22 +59,12 @@ func TestGroups(t *testing.T) {
Permission: "write",
}
group, err := c.Groups.Update(opt)
if err != nil {
t.Error(err)
}

if group.Name != name {
t.Error("The Group `name` attribute does not match the expected value.")
}
if group.AutoAdd != true {
t.Error("The Group `auto_add` attribute does not match the expected value.")
}
if group.Permission != "write" {
t.Error("The Group `permission` attribute does not match the expected value.")
}
if group.Slug != groupResourceSlug {
t.Error("The Group `slug` attribute does not match the expected value.")
}
assert.NoError(t, err)
assert.Equal(t, name, group.Name)
assert.True(t, group.AutoAdd)
assert.Equal(t, "write", group.Permission)
assert.Equal(t, groupResourceSlug, group.Slug)
})

t.Run("delete", func(t *testing.T) {
Expand All @@ -101,9 +73,7 @@ func TestGroups(t *testing.T) {
Slug: groupResourceSlug,
}
err := c.Groups.Delete(opt)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
})
}

Expand Down

0 comments on commit 6b19517

Please sign in to comment.