Commit 4c47fc56 by Arve Knudsen Committed by GitHub

Guardian: Rewrite tests from goconvey (#29292)

* Guardian: Rewrite tests from goconvey

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Update pkg/services/guardian/guardian_test.go

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
parent 27b43904
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert"
) )
type scenarioContext struct { type scenarioContext struct {
...@@ -29,12 +29,14 @@ type scenarioContext struct { ...@@ -29,12 +29,14 @@ type scenarioContext struct {
type scenarioFunc func(c *scenarioContext) type scenarioFunc func(c *scenarioContext)
func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) { func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
t.Run(desc, func(t *testing.T) {
user := &models.SignedInUser{ user := &models.SignedInUser{
UserId: userID, UserId: userID,
OrgId: orgID, OrgId: orgID,
OrgRole: role, OrgRole: role,
} }
guard := New(dashboardID, orgID, user) guard := New(dashboardID, orgID, user)
sc := &scenarioContext{ sc := &scenarioContext{
t: t, t: t,
orgRoleScenario: desc, orgRoleScenario: desc,
...@@ -42,13 +44,12 @@ func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenari ...@@ -42,13 +44,12 @@ func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenari
givenDashboardID: dashboardID, givenDashboardID: dashboardID,
g: guard, g: guard,
} }
Convey(desc, func() {
fn(sc) fn(sc)
}) })
} }
func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) { func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
t.Run(desc, func(t *testing.T) {
user := &models.SignedInUser{ user := &models.SignedInUser{
UserId: 0, UserId: 0,
OrgId: orgID, OrgId: orgID,
...@@ -64,12 +65,13 @@ func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenario ...@@ -64,12 +65,13 @@ func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenario
g: guard, g: guard,
} }
Convey(desc, func() {
fn(sc) fn(sc)
}) })
} }
func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, permissions []*models.DashboardAclInfoDTO, fn scenarioFunc) { func permissionScenario(desc string, dashboardID int64, sc *scenarioContext,
permissions []*models.DashboardAclInfoDTO, fn scenarioFunc) {
sc.t.Run(desc, func(t *testing.T) {
bus.ClearBusHandlers() bus.ClearBusHandlers()
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error { bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
...@@ -110,7 +112,6 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, per ...@@ -110,7 +112,6 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, per
sc.givenPermissions = permissions sc.givenPermissions = permissions
sc.givenTeams = teams sc.givenTeams = teams
Convey(desc, func() {
fn(sc) fn(sc)
}) })
} }
...@@ -194,7 +195,7 @@ func (f permissionFlags) String() string { ...@@ -194,7 +195,7 @@ func (f permissionFlags) String() string {
} }
func (sc *scenarioContext) reportSuccess() { func (sc *scenarioContext) reportSuccess() {
So(true, ShouldBeTrue) assert.True(sc.t, true)
} }
func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actual interface{}) { func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actual interface{}) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment