MCPcopy Create free account
hub / github.com/gogs/gogs / usersCreate

Function usersCreate

internal/database/users_test.go:382–428  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *UsersStore)

Source from the content-addressed store, hash-verified

380}
381
382func usersCreate(t *testing.T, ctx context.Context, s *UsersStore) {
383 alice, err := s.Create(
384 ctx,
385 "alice",
386 "alice@example.com",
387 CreateUserOptions{
388 Activated: true,
389 },
390 )
391 require.NoError(t, err)
392
393 t.Run("name not allowed", func(t *testing.T) {
394 _, err := s.Create(ctx, "-", "", CreateUserOptions{})
395 wantErr := ErrNameNotAllowed{
396 args: errutil.Args{
397 "reason": "reserved",
398 "name": "-",
399 },
400 }
401 assert.Equal(t, wantErr, err)
402 })
403
404 t.Run("name already exists", func(t *testing.T) {
405 _, err := s.Create(ctx, alice.Name, "", CreateUserOptions{})
406 wantErr := ErrUserAlreadyExist{
407 args: errutil.Args{
408 "name": alice.Name,
409 },
410 }
411 assert.Equal(t, wantErr, err)
412 })
413
414 t.Run("email already exists", func(t *testing.T) {
415 _, err := s.Create(ctx, "bob", alice.Email, CreateUserOptions{})
416 wantErr := ErrEmailAlreadyUsed{
417 args: errutil.Args{
418 "email": alice.Email,
419 },
420 }
421 assert.Equal(t, wantErr, err)
422 })
423
424 user, err := s.GetByUsername(ctx, alice.Name)
425 require.NoError(t, err)
426 assert.Equal(t, s.db.NowFunc().Format(time.RFC3339), user.Created.UTC().Format(time.RFC3339))
427 assert.Equal(t, s.db.NowFunc().Format(time.RFC3339), user.Updated.UTC().Format(time.RFC3339))
428}
429
430func usersDeleteCustomAvatar(t *testing.T, ctx context.Context, s *UsersStore) {
431 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})

Callers

nothing calls this directly

Calls 2

GetByUsernameMethod · 0.80
CreateMethod · 0.45

Tested by

no test coverage detected