package gpaste_test import ( "testing" "git.t-juice.club/torjus/gpaste" ) func RunUserStoreTest(newFunc func() (func(), gpaste.UserStore), t *testing.T) { t.Run("Basics", func(t *testing.T) { cleanup, s := newFunc() t.Cleanup(cleanup) userMap := make(map[string]string) for i := 0; i < 10; i++ { userMap[randomString(8)] = randomString(16) } for k, v := range userMap { user := &gpaste.User{ Username: k, } if err := user.SetPassword(v); err != nil { t.Fatalf("Error setting password: %s", err) } if err := s.Store(user); err != nil { t.Fatalf("Error storing user: %s", err) } } for k, v := range userMap { user, err := s.Get(k) if err != nil { t.Errorf("Error getting user: %s", err) } if err := user.ValidatePassword(v); err != nil { t.Errorf("Error verifying password: %s", err) } } }) }