auth
2014-09-01
Child:14599a5c7819
auth/grant_test.go
Implement GrantStore for Memstore. Fix bug in GrantStore that asks for a UUID when it really wants a string. Implement GrantStore interface in Memstore, including unit tests for successful (i.e., works-as-intended) scenarios.
| paddy@29 | 1 package auth |
| paddy@29 | 2 |
| paddy@29 | 3 import ( |
| paddy@29 | 4 "testing" |
| paddy@29 | 5 "time" |
| paddy@29 | 6 |
| paddy@29 | 7 "secondbit.org/uuid" |
| paddy@29 | 8 ) |
| paddy@29 | 9 |
| paddy@29 | 10 var grantStores = []GrantStore{NewMemstore()} |
| paddy@29 | 11 |
| paddy@29 | 12 func TestGrantStoreSuccess(t *testing.T) { |
| paddy@29 | 13 grant := Grant{ |
| paddy@29 | 14 Code: "code", |
| paddy@29 | 15 Created: time.Now(), |
| paddy@29 | 16 ExpiresIn: 180, |
| paddy@29 | 17 ClientID: uuid.NewID(), |
| paddy@29 | 18 Scope: "scope", |
| paddy@29 | 19 RedirectURI: "redirectURI", |
| paddy@29 | 20 State: "state", |
| paddy@29 | 21 } |
| paddy@29 | 22 for pos, store := range grantStores { |
| paddy@29 | 23 err := store.SaveGrant(grant) |
| paddy@29 | 24 if err != nil { |
| paddy@29 | 25 t.Errorf("Error saving grant in GrantStore #%d: %s", pos, err) |
| paddy@29 | 26 } |
| paddy@29 | 27 retrieved, err := store.GetGrant(grant.Code) |
| paddy@29 | 28 if err != nil { |
| paddy@29 | 29 t.Errorf("Error retrieving grant in GrantStore #%d: %s", pos, err) |
| paddy@29 | 30 } |
| paddy@29 | 31 t.Log(retrieved) |
| paddy@29 | 32 // TODO: compare retrieved to grant |
| paddy@29 | 33 err = store.DeleteGrant(grant.Code) |
| paddy@29 | 34 if err != nil { |
| paddy@29 | 35 t.Errorf("Error removing grant from GrantStore #%d: %s", pos, err) |
| paddy@29 | 36 } |
| paddy@29 | 37 retrieved, err = store.GetGrant(grant.Code) |
| paddy@29 | 38 if err != ErrGrantNotFound { |
| paddy@29 | 39 t.Errorf("Expected ErrGrantNotFound from GrantStore #%d, got %+v and %+v", pos, retrieved, err) |
| paddy@29 | 40 } |
| paddy@29 | 41 } |
| paddy@29 | 42 } |