(t *testing.T)
| 216 | } |
| 217 | |
| 218 | func TestUserRolesToRemovePickerOptions(t *testing.T) { |
| 219 | tests := []struct { |
| 220 | name string |
| 221 | userID string |
| 222 | userRoles []*management.Role |
| 223 | apiError error |
| 224 | assertOutput func(t testing.TB, options []string) |
| 225 | assertError func(t testing.TB, err error) |
| 226 | }{ |
| 227 | { |
| 228 | name: "happy path", |
| 229 | userRoles: []*management.Role{ |
| 230 | { |
| 231 | ID: auth0.String("some-id-1"), |
| 232 | Name: auth0.String("some-name-1"), |
| 233 | }, |
| 234 | { |
| 235 | ID: auth0.String("some-id-2"), |
| 236 | Name: auth0.String("some-name-2"), |
| 237 | }, |
| 238 | }, |
| 239 | assertOutput: func(t testing.TB, options []string) { |
| 240 | assert.Len(t, options, 2) |
| 241 | assert.Equal(t, "some-id-1 (Name: some-name-1)", options[0]) |
| 242 | assert.Equal(t, "some-id-2 (Name: some-name-2)", options[1]) |
| 243 | }, |
| 244 | assertError: func(t testing.TB, err error) { |
| 245 | t.Fail() |
| 246 | }, |
| 247 | }, |
| 248 | { |
| 249 | name: "no roles for user", |
| 250 | userRoles: []*management.Role{}, |
| 251 | assertOutput: func(t testing.TB, options []string) { |
| 252 | assert.Empty(t, options) |
| 253 | }, |
| 254 | assertError: func(t testing.TB, err error) { |
| 255 | t.Fail() |
| 256 | }, |
| 257 | }, |
| 258 | { |
| 259 | name: "API error", |
| 260 | userID: "some-id", |
| 261 | apiError: errors.New("error"), |
| 262 | assertOutput: func(t testing.TB, options []string) { |
| 263 | t.Fail() |
| 264 | }, |
| 265 | assertError: func(t testing.TB, err error) { |
| 266 | assert.ErrorContains(t, err, "failed to read the current roles for user with ID \"some-id\": error") |
| 267 | }, |
| 268 | }, |
| 269 | } |
| 270 | |
| 271 | for _, test := range tests { |
| 272 | t.Run(test.name, func(t *testing.T) { |
| 273 | ctrl := gomock.NewController(t) |
| 274 | defer ctrl.Finish() |
| 275 |
nothing calls this directly
no test coverage detected