auth

Paddy 2014-10-26 Parent:3a6a65ed380c Child:a8b86f5fba78

57:e45bfa2abc00 Go to Latest

auth/token_test.go

The great documentation and exported interface cleanup. Modify all our *Store interfaces to be unexported, as there's no real good reason they need to be exported, especially as they can be implemented without being exported. The interfaces shouldn't matter to 99% of users of the package, so let's not pollute our package API. Further, all methods of the interfaces are now unexported, for pretty much the same reasoning. Add a doc.go file with documentation explaining the choices the package is making and what it provides. Implement documentation on all our exported types and methods and functions, which makes golint happy. The only remaining golint warning is about NewMemstore, which will stay the way it is. The memstore type is useful outside tests for things like standing up a server quickly when we don't care about the storage, and because the type is unexported, we _need_ a New function to create an instance that can be passed to the Context.

History
     1.1 --- a/token_test.go	Wed Oct 22 00:30:28 2014 -0400
     1.2 +++ b/token_test.go	Sun Oct 26 00:53:36 2014 -0400
     1.3 @@ -7,7 +7,7 @@
     1.4  	"code.secondbit.org/uuid"
     1.5  )
     1.6  
     1.7 -var tokenStores = []TokenStore{NewMemstore()}
     1.8 +var tokenStores = []tokenStore{NewMemstore()}
     1.9  
    1.10  func compareTokens(token1, token2 Token) (success bool, field string, val1, val2 interface{}) {
    1.11  	if token1.AccessToken != token2.AccessToken {
    1.12 @@ -46,15 +46,15 @@
    1.13  		ProfileID:    uuid.NewID(),
    1.14  	}
    1.15  	for _, store := range tokenStores {
    1.16 -		err := store.SaveToken(token)
    1.17 +		err := store.saveToken(token)
    1.18  		if err != nil {
    1.19  			t.Errorf("Error saving token to %T: %s", store, err)
    1.20  		}
    1.21 -		err = store.SaveToken(token)
    1.22 +		err = store.saveToken(token)
    1.23  		if err != ErrTokenAlreadyExists {
    1.24  			t.Errorf("Expected ErrTokenAlreadyExists from %T, got %s", store, err)
    1.25  		}
    1.26 -		retrievedAccess, err := store.GetToken(token.AccessToken, false)
    1.27 +		retrievedAccess, err := store.getToken(token.AccessToken, false)
    1.28  		if err != nil {
    1.29  			t.Errorf("Error retrieving token from %T: %s", store, err)
    1.30  		}
    1.31 @@ -62,7 +62,7 @@
    1.32  		if !success {
    1.33  			t.Errorf("Expected field %s to be %v, but got %v from %T", field, expectation, result, store)
    1.34  		}
    1.35 -		retrievedRefresh, err := store.GetToken(token.RefreshToken, true)
    1.36 +		retrievedRefresh, err := store.getToken(token.RefreshToken, true)
    1.37  		if err != nil {
    1.38  			t.Errorf("Error retrieving refresh token from %T: %s", store, err)
    1.39  		}
    1.40 @@ -70,7 +70,7 @@
    1.41  		if !success {
    1.42  			t.Errorf("Expected field %s to be %v, but got %v from %T", field, expectation, result, store)
    1.43  		}
    1.44 -		retrievedProfile, err := store.GetTokensByProfileID(token.ProfileID, 25, 0)
    1.45 +		retrievedProfile, err := store.getTokensByProfileID(token.ProfileID, 25, 0)
    1.46  		if err != nil {
    1.47  			t.Errorf("Error retrieving token by profile from %T: %s", store, err)
    1.48  		}
    1.49 @@ -81,26 +81,26 @@
    1.50  		if !success {
    1.51  			t.Errorf("Expected field %s to be %v, but got %v from %T", field, expectation, result, store)
    1.52  		}
    1.53 -		err = store.RemoveToken(token.AccessToken)
    1.54 +		err = store.removeToken(token.AccessToken)
    1.55  		if err != nil {
    1.56  			t.Errorf("Error removing token from %T: %s", store, err)
    1.57  		}
    1.58 -		_, err = store.GetToken(token.AccessToken, false)
    1.59 +		_, err = store.getToken(token.AccessToken, false)
    1.60  		if err != ErrTokenNotFound {
    1.61  			t.Errorf("Expected ErrTokenNotFound from %T, got %s", store, err)
    1.62  		}
    1.63 -		_, err = store.GetToken(token.RefreshToken, true)
    1.64 +		_, err = store.getToken(token.RefreshToken, true)
    1.65  		if err != ErrTokenNotFound {
    1.66  			t.Errorf("Expected ErrTokenNotFound from %T, got %s", store, err)
    1.67  		}
    1.68 -		retrievedProfile, err = store.GetTokensByProfileID(token.ProfileID, 25, 0)
    1.69 +		retrievedProfile, err = store.getTokensByProfileID(token.ProfileID, 25, 0)
    1.70  		if err != nil {
    1.71  			t.Errorf("Error retrieving token by profile from %T: %s", store, err)
    1.72  		}
    1.73  		if len(retrievedProfile) != 0 {
    1.74  			t.Errorf("Expected list of 0 tokens from %T, got %+v", store, retrievedProfile)
    1.75  		}
    1.76 -		err = store.RemoveToken(token.AccessToken)
    1.77 +		err = store.removeToken(token.AccessToken)
    1.78  		if err != ErrTokenNotFound {
    1.79  			t.Errorf("Expected ErrTokenNotFound from %T, got %s", store, err)
    1.80  		}