MCPcopy
hub / github.com/kopia/kopia / TestUserManager

Function TestUserManager

internal/user/user_manager_test.go:13–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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
62func TestGetNewProfile(t *testing.T) {
63 ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant)

Callers

nothing calls this directly

Calls 6

NewEnvironmentFunction · 0.92
GetUserProfileFunction · 0.92
SetUserProfileFunction · 0.92
DeleteUserProfileFunction · 0.92
FatalfMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected