auth

Paddy 2015-03-24 Parent:e090a69e711f Child:3e8964a914ef

152:de5e09680f6b Go to Latest

auth/scope_test.go

Implement postgres version of scopeStore. Update the authd server to use postgres as its scopeStore, instead of memstore. panic when starting the authd server if the CreateScopes call fails. This should, ideally, ignore ErrScopeAlreadyExists errors, but does not as of this commit. Update the simple.gotmpl template to properly display scopes, after switching to the Scope type instead of simply passing around the string the client supplied broke the template and I never bothered fixing it. Update the updateScopes method on the scopeStore (and the corresponding UpdateScopes method on the Context type) to be updateScope/UpdateScope. Operating on several scopes at a time like that is simply too challenging in SQL and I can't justify the complexity with a use case. Add a helper method to ScopeChange called Empty(), which returns true if the ScopeChange is full of nil values. Remove the ID from the ScopeChange type, because we're no longer accepting multiple ScopeChange types in UpdateScope, so we can supply that information outside the ScopeChange, which matches the rest of our update* methods. Correct our tests in scope_test.go to correctly use the updateScope method instead of the old updateScopes method. This generally just resulted in calling updateScope multiple times, as opposed to just once. Add a scope table initialization to the sql/postgres_init.sql script.

History
     1.1 --- a/scope_test.go	Sun Mar 22 16:26:37 2015 -0400
     1.2 +++ b/scope_test.go	Tue Mar 24 20:39:03 2015 -0400
     1.3 @@ -36,15 +36,12 @@
     1.4  	updatedName := "Updated Scope"
     1.5  	updatedDescription := "An updated scope."
     1.6  	update := ScopeChange{
     1.7 -		ID:   scope.ID,
     1.8  		Name: &updatedName,
     1.9  	}
    1.10  	update2 := ScopeChange{
    1.11 -		ID:          scope2.ID,
    1.12  		Description: &updatedDescription,
    1.13  	}
    1.14  	update3 := ScopeChange{
    1.15 -		ID:          scope3.ID,
    1.16  		Name:        &updatedName,
    1.17  		Description: &updatedDescription,
    1.18  	}
    1.19 @@ -110,23 +107,21 @@
    1.20  				t.Errorf("Expected %s to be %+v for scope %s, got %+v from %T", field, val1, s.ID, val2, store)
    1.21  			}
    1.22  		}
    1.23 -		updated, err := context.UpdateScopes([]ScopeChange{update, update2, update3})
    1.24 +		err = context.UpdateScope(scope.ID, update)
    1.25  		if err != nil {
    1.26 -			t.Errorf("Unexpected error updating scopes in %T: %+v", store, err)
    1.27 -		}
    1.28 -		if len(updated) != 3 {
    1.29 -			t.Logf("%+v", updated)
    1.30 -			t.Errorf("Expected %d results, got %d from %T", 3, len(updated), store)
    1.31 +			t.Errorf("Unexpected error updating scope in %T: %+v", store, err)
    1.32  		}
    1.33  		scope.ApplyChange(update)
    1.34 +		err = context.UpdateScope(scope2.ID, update2)
    1.35 +		if err != nil {
    1.36 +			t.Errorf("Unexpected error updating scope in %T: %+v", store, err)
    1.37 +		}
    1.38  		scope2.ApplyChange(update2)
    1.39 +		err = context.UpdateScope(scope3.ID, update3)
    1.40 +		if err != nil {
    1.41 +			t.Errorf("Unexpected error updating scope in %T: %+v", store, err)
    1.42 +		}
    1.43  		scope3.ApplyChange(update3)
    1.44 -		for pos, s := range []Scope{scope, scope2, scope3} {
    1.45 -			success, field, val1, val2 = compareScopes(s, updated[pos])
    1.46 -			if !success {
    1.47 -				t.Errorf("Expected %s to be %+v for scope %s, got %+v from %T", field, val1, s.ID, val2, store)
    1.48 -			}
    1.49 -		}
    1.50  		retrieved, err = context.ListScopes()
    1.51  		if err != nil {
    1.52  			t.Errorf("Unexpected error retrieving scopes from %T: %+v", store, err)
    1.53 @@ -167,7 +162,7 @@
    1.54  				t.Errorf("Expected error to be for scope ID %s, but got %s from %T", scope.ID, e.ID, store)
    1.55  			}
    1.56  		}
    1.57 -		updated, err = context.UpdateScopes([]ScopeChange{update})
    1.58 +		err = context.UpdateScope(scope.ID, update)
    1.59  		if err == nil {
    1.60  			t.Errorf("No error returned updating non-existent scopes from %T", store)
    1.61  		}