From 1f1162f1d8c3bbd3f25a3bcd3110e01dfa7fec8b Mon Sep 17 00:00:00 2001 From: Serge Zaitsev Date: Tue, 26 Oct 2021 17:59:37 +0200 Subject: [PATCH] Chore: Refactor GoConvey in teamguardian package (#40896) * refactor goconvey in teamguardian package * use proper order of parameters in equality assertion Co-authored-by: ying-jeanne <74549700+ying-jeanne@users.noreply.github.com> Co-authored-by: ying-jeanne <74549700+ying-jeanne@users.noreply.github.com> --- pkg/services/teamguardian/teams_test.go | 29 +++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/services/teamguardian/teams_test.go b/pkg/services/teamguardian/teams_test.go index 358e1fc3c80..e79e3f1a689 100644 --- a/pkg/services/teamguardian/teams_test.go +++ b/pkg/services/teamguardian/teams_test.go @@ -5,11 +5,12 @@ import ( "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/models" - . "github.com/smartystreets/goconvey/convey" + + "github.com/stretchr/testify/require" ) func TestUpdateTeam(t *testing.T) { - Convey("Updating a team", t, func() { + t.Run("Updating a team", func(t *testing.T) { bus.ClearBusHandlers() admin := models.SignedInUser{ @@ -27,20 +28,20 @@ func TestUpdateTeam(t *testing.T) { OrgId: 1, } - Convey("Given an editor and a team he isn't a member of", func() { - Convey("Should not be able to update the team", func() { + t.Run("Given an editor and a team he isn't a member of", func(t *testing.T) { + t.Run("Should not be able to update the team", func(t *testing.T) { bus.AddHandler("test", func(cmd *models.GetTeamMembersQuery) error { cmd.Result = []*models.TeamMemberDTO{} return nil }) err := CanAdmin(bus.GetBus(), testTeam.OrgId, testTeam.Id, &editor) - So(err, ShouldEqual, models.ErrNotAllowedToUpdateTeam) + require.Equal(t, models.ErrNotAllowedToUpdateTeam, err) }) }) - Convey("Given an editor and a team he is an admin in", func() { - Convey("Should be able to update the team", func() { + t.Run("Given an editor and a team he is an admin in", func(t *testing.T) { + t.Run("Should be able to update the team", func(t *testing.T) { bus.AddHandler("test", func(cmd *models.GetTeamMembersQuery) error { cmd.Result = []*models.TeamMemberDTO{{ OrgId: testTeam.OrgId, @@ -52,17 +53,17 @@ func TestUpdateTeam(t *testing.T) { }) err := CanAdmin(bus.GetBus(), testTeam.OrgId, testTeam.Id, &editor) - So(err, ShouldBeNil) + require.NoError(t, err) }) }) - Convey("Given an editor and a team in another org", func() { + t.Run("Given an editor and a team in another org", func(t *testing.T) { testTeamOtherOrg := models.Team{ Id: 1, OrgId: 2, } - Convey("Shouldn't be able to update the team", func() { + t.Run("Shouldn't be able to update the team", func(t *testing.T) { bus.AddHandler("test", func(cmd *models.GetTeamMembersQuery) error { cmd.Result = []*models.TeamMemberDTO{{ OrgId: testTeamOtherOrg.OrgId, @@ -74,14 +75,14 @@ func TestUpdateTeam(t *testing.T) { }) err := CanAdmin(bus.GetBus(), testTeamOtherOrg.OrgId, testTeamOtherOrg.Id, &editor) - So(err, ShouldEqual, models.ErrNotAllowedToUpdateTeamInDifferentOrg) + require.Equal(t, models.ErrNotAllowedToUpdateTeamInDifferentOrg, err) }) }) - Convey("Given an org admin and a team", func() { - Convey("Should be able to update the team", func() { + t.Run("Given an org admin and a team", func(t *testing.T) { + t.Run("Should be able to update the team", func(t *testing.T) { err := CanAdmin(bus.GetBus(), testTeam.OrgId, testTeam.Id, &admin) - So(err, ShouldBeNil) + require.NoError(t, err) }) }) })