(t *testing.T, ctx context.Context, s *UsersStore)
| 227 | } |
| 228 | |
| 229 | func usersChangeUsername(t *testing.T, ctx context.Context, s *UsersStore) { |
| 230 | alice, err := s.Create( |
| 231 | ctx, |
| 232 | "alice", |
| 233 | "alice@example.com", |
| 234 | CreateUserOptions{ |
| 235 | Activated: true, |
| 236 | }, |
| 237 | ) |
| 238 | require.NoError(t, err) |
| 239 | |
| 240 | t.Run("name not allowed", func(t *testing.T) { |
| 241 | err := s.ChangeUsername(ctx, alice.ID, "-") |
| 242 | wantErr := ErrNameNotAllowed{ |
| 243 | args: errutil.Args{ |
| 244 | "reason": "reserved", |
| 245 | "name": "-", |
| 246 | }, |
| 247 | } |
| 248 | assert.Equal(t, wantErr, err) |
| 249 | }) |
| 250 | |
| 251 | t.Run("name already exists", func(t *testing.T) { |
| 252 | bob, err := s.Create( |
| 253 | ctx, |
| 254 | "bob", |
| 255 | "bob@example.com", |
| 256 | CreateUserOptions{ |
| 257 | Activated: true, |
| 258 | }, |
| 259 | ) |
| 260 | require.NoError(t, err) |
| 261 | |
| 262 | err = s.ChangeUsername(ctx, alice.ID, bob.Name) |
| 263 | wantErr := ErrUserAlreadyExist{ |
| 264 | args: errutil.Args{ |
| 265 | "name": bob.Name, |
| 266 | }, |
| 267 | } |
| 268 | assert.Equal(t, wantErr, err) |
| 269 | }) |
| 270 | |
| 271 | tempRepositoryRoot := filepath.Join(os.TempDir(), "usersChangeUsername-tempRepositoryRoot") |
| 272 | conf.SetMockRepository( |
| 273 | t, |
| 274 | conf.RepositoryOpts{ |
| 275 | Root: tempRepositoryRoot, |
| 276 | }, |
| 277 | ) |
| 278 | err = os.RemoveAll(tempRepositoryRoot) |
| 279 | require.NoError(t, err) |
| 280 | defer func() { _ = os.RemoveAll(tempRepositoryRoot) }() |
| 281 | |
| 282 | tempServerAppDataPath := filepath.Join(os.TempDir(), "usersChangeUsername-tempServerAppDataPath") |
| 283 | conf.SetMockServer( |
| 284 | t, |
| 285 | conf.ServerOpts{ |
| 286 | AppDataPath: tempServerAppDataPath, |
nothing calls this directly
no test coverage detected