~gophers/goose/unstable-001

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package client_test

import (
	. "launchpad.net/gocheck"
	"launchpad.net/~gophers/goose/unstable-001/identity"
	"launchpad.net/~gophers/goose/unstable-001/testing/httpsuite"
	"launchpad.net/~gophers/goose/unstable-001/testservices/identityservice"
	"net/http"
)

func registerLocalTests(authMethods []identity.AuthMethod) {
	for _, authMethod := range authMethods {
		Suite(&localLiveSuite{
			LiveTests: LiveTests{
				authMethod: authMethod,
			},
		})
	}
}

// localLiveSuite runs tests from LiveTests using a fake
// identity server that runs within the test process itself.
type localLiveSuite struct {
	LiveTests
	// The following attributes are for using testing doubles.
	httpsuite.HTTPSuite
	identityDouble http.Handler
}

func (s *localLiveSuite) SetUpSuite(c *C) {
	c.Logf("Using identity service test double")
	s.HTTPSuite.SetUpSuite(c)
	s.cred = &identity.Credentials{
		URL:     s.Server.URL,
		User:    "fred",
		Secrets: "secret",
		Region:  "some region"}
	switch s.authMethod {
	default:
		panic("Invalid authentication method")
	case identity.AuthUserPass:
		s.identityDouble = identityservice.NewUserPass()
		s.identityDouble.(*identityservice.UserPass).AddUser(s.cred.User, s.cred.Secrets)
	case identity.AuthLegacy:
		s.identityDouble = identityservice.NewLegacy()
		var legacy = s.identityDouble.(*identityservice.Legacy)
		legacy.AddUser(s.cred.User, s.cred.Secrets)
		legacy.SetManagementURL("http://management/url")
	}
	s.LiveTests.SetUpSuite(c)
}

func (s *localLiveSuite) TearDownSuite(c *C) {
	s.LiveTests.TearDownSuite(c)
	s.HTTPSuite.TearDownSuite(c)
}

func (s *localLiveSuite) SetUpTest(c *C) {
	s.HTTPSuite.SetUpTest(c)
	s.Mux.Handle("/", s.identityDouble)
	s.LiveTests.SetUpTest(c)
}

func (s *localLiveSuite) TearDownTest(c *C) {
	s.LiveTests.TearDownTest(c)
	s.HTTPSuite.TearDownTest(c)
}

// Additional tests to be run against the service double only go here.