auth
auth/grant_test.go
Add more tests for ClientStores. Test that deleting a client that doesn't exist throws an ErrClientNotFound. Test that adding a client twice returns an ErrClientAlreadyExists. Test that clients retrieve have properties that all match the client that was stored. Remove the unused error return from the internal MemoryStore helper for getting a list of clients by their OwnerID. If a profile doesn't exist, return an empty list of clients, as we're technically returning any client that has that OwnerID. There's no guarantee that that OwnerID is actually valid.
1 package auth
3 import (
4 "testing"
5 "time"
7 "secondbit.org/uuid"
8 )
10 var grantStores = []GrantStore{NewMemstore()}
12 func TestGrantStoreSuccess(t *testing.T) {
13 grant := Grant{
14 Code: "code",
15 Created: time.Now(),
16 ExpiresIn: 180,
17 ClientID: uuid.NewID(),
18 Scope: "scope",
19 RedirectURI: "redirectURI",
20 State: "state",
21 }
22 for pos, store := range grantStores {
23 err := store.SaveGrant(grant)
24 if err != nil {
25 t.Errorf("Error saving grant in GrantStore #%d: %s", pos, err)
26 }
27 retrieved, err := store.GetGrant(grant.Code)
28 if err != nil {
29 t.Errorf("Error retrieving grant in GrantStore #%d: %s", pos, err)
30 }
31 t.Log(retrieved)
32 // TODO: compare retrieved to grant
33 err = store.DeleteGrant(grant.Code)
34 if err != nil {
35 t.Errorf("Error removing grant from GrantStore #%d: %s", pos, err)
36 }
37 retrieved, err = store.GetGrant(grant.Code)
38 if err != ErrGrantNotFound {
39 t.Errorf("Expected ErrGrantNotFound from GrantStore #%d, got %+v and %+v", pos, retrieved, err)
40 }
41 }
42 }