~go-bot/goose/trunk

« back to all changes in this revision

Viewing changes to identity/userpass_test.go

Goose test infrastructure improvements

This branch improves the usabilty of the goose test infrastructure.

A full Openstack service test double is provided. A bunch of manual coding which was required in each test suite to set up various Openstack module test doubles is replaced by a few lines of code.

New code:

        cred := &identity.Credentials{...}
        openstack := openstack.New(cred)
        openstack.SetupHTTP(s.Mux)

Old code:

        // Create the identity service.
        s.identityDouble = identityservice.NewUserPass()
        token := s.identityDouble.AddUser(s.cred.User, s.cred.Secrets)
        s.Mux.Handle(baseIdentityURL, s.identityDouble)

        // Register Swift endpoints with identity service.
        ep := identityservice.Endpoint{
                AdminURL:    s.Server.URL + baseSwiftURL,
                InternalURL: s.Server.URL + baseSwiftURL,
                PublicURL:   s.Server.URL + baseSwiftURL,
                Region:      s.cred.Region,
        }
        service := identityservice.Service{"swift", "object-store", []identityservice.Endpoint{ep}}
        s.identityDouble.AddService(service)
        s.swiftDouble = swiftservice.New("localhost", baseSwiftURL+"/", token)
        s.Mux.Handle(baseSwiftURL+"/", s.swiftDouble)

        // Register Nova endpoints with identity service.
        ep = identityservice.Endpoint{
                AdminURL:    s.Server.URL + baseNovaURL,
                InternalURL: s.Server.URL + baseNovaURL,
                PublicURL:   s.Server.URL + baseNovaURL,
                Region:      s.cred.Region,
        }
        service = identityservice.Service{"nova", "compute", []identityservice.Endpoint{ep}}
        s.identityDouble.AddService(service)
        s.novaDouble = novaservice.New("localhost", "V1", token, "1")
        s.novaDouble.SetupHTTP(s.Mux)
        
        
Other changes include:

- fix the identity service double to remove the hard coded userId and tenantId.
- do not hard code a fixed token against a service double - each user is assigned their own token just like a real instance, allowing multi-user tests to be written.
- improvements to the Swift service double to make it use URLs which are compliant with how a real Swift instance would do it.
- factor out a common base class for the legacy and userpass double implementations.
- use a SetupHTTP() for all test doubles instead of requiring the coder to know the magic URL paths to use.

R=dimitern
CC=
https://codereview.appspot.com/7194043

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
func (s *UserPassTestSuite) TestAuthAgainstServer(c *C) {
16
16
        service := identityservice.NewUserPass()
17
 
        s.Mux.Handle("/", service)
18
 
        token := service.AddUser("joe-user", "secrets")
 
17
        service.SetupHTTP(s.Mux)
 
18
        userInfo := service.AddUser("joe-user", "secrets", "tenant")
19
19
        var l Authenticator = &UserPass{}
20
 
        creds := Credentials{User: "joe-user", URL: s.Server.URL, Secrets: "secrets"}
 
20
        creds := Credentials{User: "joe-user", URL: s.Server.URL + "/tokens", Secrets: "secrets"}
21
21
        auth, err := l.Auth(&creds)
22
22
        c.Assert(err, IsNil)
23
 
        c.Assert(auth.Token, Equals, token)
24
 
        // c.Assert(auth.ServiceURLs, DeepEquals, map[string]string{"compute": "http://management.test.invalid/url"})
 
23
        c.Assert(auth.Token, Equals, userInfo.Token)
 
24
        c.Assert(auth.TenantId, Equals, userInfo.TenantId)
25
25
}