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