auth

Paddy 2014-09-01 Child:14599a5c7819

29:5bf0a5fd1d01 Go to Latest

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.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/grant_test.go	Mon Sep 01 09:49:23 2014 -0400
     1.3 @@ -0,0 +1,42 @@
     1.4 +package auth
     1.5 +
     1.6 +import (
     1.7 +	"testing"
     1.8 +	"time"
     1.9 +
    1.10 +	"secondbit.org/uuid"
    1.11 +)
    1.12 +
    1.13 +var grantStores = []GrantStore{NewMemstore()}
    1.14 +
    1.15 +func TestGrantStoreSuccess(t *testing.T) {
    1.16 +	grant := Grant{
    1.17 +		Code:        "code",
    1.18 +		Created:     time.Now(),
    1.19 +		ExpiresIn:   180,
    1.20 +		ClientID:    uuid.NewID(),
    1.21 +		Scope:       "scope",
    1.22 +		RedirectURI: "redirectURI",
    1.23 +		State:       "state",
    1.24 +	}
    1.25 +	for pos, store := range grantStores {
    1.26 +		err := store.SaveGrant(grant)
    1.27 +		if err != nil {
    1.28 +			t.Errorf("Error saving grant in GrantStore #%d: %s", pos, err)
    1.29 +		}
    1.30 +		retrieved, err := store.GetGrant(grant.Code)
    1.31 +		if err != nil {
    1.32 +			t.Errorf("Error retrieving grant in GrantStore #%d: %s", pos, err)
    1.33 +		}
    1.34 +		t.Log(retrieved)
    1.35 +		// TODO: compare retrieved to grant
    1.36 +		err = store.DeleteGrant(grant.Code)
    1.37 +		if err != nil {
    1.38 +			t.Errorf("Error removing grant from GrantStore #%d: %s", pos, err)
    1.39 +		}
    1.40 +		retrieved, err = store.GetGrant(grant.Code)
    1.41 +		if err != ErrGrantNotFound {
    1.42 +			t.Errorf("Expected ErrGrantNotFound from GrantStore #%d, got %+v and %+v", pos, retrieved, err)
    1.43 +		}
    1.44 +	}
    1.45 +}