(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestUserManager(t *testing.T) { |
| 14 | ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) |
| 15 | |
| 16 | if _, err := user.GetUserProfile(ctx, env.RepositoryWriter, "alice@somehost"); !errors.Is(err, user.ErrUserNotFound) { |
| 17 | t.Fatalf("unexpected error: %v", err) |
| 18 | } |
| 19 | |
| 20 | require.NoError(t, user.SetUserProfile(ctx, env.RepositoryWriter, &user.Profile{ |
| 21 | Username: "alice@somehost", |
| 22 | PasswordHash: []byte("hahaha"), |
| 23 | })) |
| 24 | |
| 25 | if _, err := user.GetUserProfile(ctx, env.RepositoryWriter, "bob"); !errors.Is(err, user.ErrUserNotFound) { |
| 26 | t.Fatalf("unexpected error: %v", err) |
| 27 | } |
| 28 | |
| 29 | a, err := user.GetUserProfile(ctx, env.RepositoryWriter, "alice@somehost") |
| 30 | if err != nil { |
| 31 | t.Fatalf("unexpected error: %v", err) |
| 32 | } |
| 33 | |
| 34 | if got, want := string(a.PasswordHash), "hahaha"; got != want { |
| 35 | t.Errorf("unexpected password hash: %v, want %v", got, want) |
| 36 | } |
| 37 | |
| 38 | require.NoError(t, user.SetUserProfile(ctx, env.RepositoryWriter, &user.Profile{ |
| 39 | Username: "alice@somehost", |
| 40 | PasswordHash: []byte("hehehehe"), |
| 41 | })) |
| 42 | |
| 43 | a, err = user.GetUserProfile(ctx, env.RepositoryWriter, "alice@somehost") |
| 44 | if err != nil { |
| 45 | t.Fatalf("unexpected error: %v", err) |
| 46 | } |
| 47 | |
| 48 | if got, want := string(a.PasswordHash), "hehehehe"; got != want { |
| 49 | t.Errorf("unexpected password hash: %v, want %v", got, want) |
| 50 | } |
| 51 | |
| 52 | err = user.DeleteUserProfile(ctx, env.RepositoryWriter, "alice@somehost") |
| 53 | if err != nil { |
| 54 | t.Fatalf("unexpected error: %v", err) |
| 55 | } |
| 56 | |
| 57 | if _, err = user.GetUserProfile(ctx, env.RepositoryWriter, "alice@somehost"); !errors.Is(err, user.ErrUserNotFound) { |
| 58 | t.Fatalf("unexpected error: %v", err) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestGetNewProfile(t *testing.T) { |
| 63 | ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) |
nothing calls this directly
no test coverage detected