~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
70
71
package swift_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"
	"launchpad.net/~gophers/goose/unstable-001/testservices/swiftservice"
	"net/http"
)

func registerLocalTests() {
	Suite(&localLiveSuite{})
}

const (
	baseURL = "/object-store"
)

// localLiveSuite runs tests from LiveTests using a fake
// swift 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
	swiftDouble    http.Handler
}

func (s *localLiveSuite) SetUpSuite(c *C) {
	c.Logf("Using identity and swift service test doubles")
	s.HTTPSuite.SetUpSuite(c)
	s.cred = &identity.Credentials{
		URL:     s.Server.URL,
		User:    "fred",
		Secrets: "secret",
		Region:  "some region"}
	// Create an identity service and register a Swift endpoint.
	s.identityDouble = identityservice.NewUserPass()
	token := s.identityDouble.(*identityservice.UserPass).AddUser(s.cred.User, s.cred.Secrets)
	ep := identityservice.Endpoint{
		s.Server.URL + baseURL, //admin
		s.Server.URL + baseURL, //internal
		s.Server.URL + baseURL, //public
		s.cred.Region,
	}
	service := identityservice.Service{"swift", "object-store", []identityservice.Endpoint{ep}}
	s.identityDouble.(*identityservice.UserPass).AddService(service)
	// Create a swift service at the registered endpoint.
	s.swiftDouble = swiftservice.New("localhost", baseURL+"/", token)
	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(baseURL+"/", s.swiftDouble)
	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.