github.com/jxgolibs/go-oauth2-server@v1.0.1/oauth/role_test.go (about)

     1  package oauth_test
     2  
     3  import (
     4  	"github.com/RichardKnop/go-oauth2-server/models"
     5  	"github.com/RichardKnop/go-oauth2-server/oauth"
     6  	"github.com/RichardKnop/go-oauth2-server/oauth/roles"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func (suite *OauthTestSuite) TestFindRoleByID() {
    11  	var (
    12  		role *models.OauthRole
    13  		err  error
    14  	)
    15  
    16  	// Let's try to find a role by a bogus ID
    17  	role, err = suite.service.FindRoleByID("bogus")
    18  
    19  	// Role should be nil
    20  	assert.Nil(suite.T(), role)
    21  
    22  	// Correct error should be returned
    23  	if assert.NotNil(suite.T(), err) {
    24  		assert.Equal(suite.T(), oauth.ErrRoleNotFound, err)
    25  	}
    26  
    27  	// Now let's pass a valid ID
    28  	role, err = suite.service.FindRoleByID(roles.User)
    29  
    30  	// Error should be nil
    31  	assert.Nil(suite.T(), err)
    32  
    33  	// Correct role should be returned
    34  	if assert.NotNil(suite.T(), role) {
    35  		assert.Equal(suite.T(), roles.User, role.ID)
    36  	}
    37  }