示例#1
0
func (m *Mother) SpaceStrategy() services.SpaceStrategy {
	env := NewEnvironment()
	uaaClient := uaa.NewZonedUAAClient(env.UAAClientID, env.UAAClientSecret, env.VerifySSL, UAAPublicKey)
	cloudController := cf.NewCloudController(env.CCHost, !env.VerifySSL)

	tokenLoader := uaa.NewTokenLoader(uaaClient)
	spaceLoader := services.NewSpaceLoader(cloudController)
	organizationLoader := services.NewOrganizationLoader(cloudController)
	enqueuer := m.Enqueuer()
	findsUserGUIDs := services.NewFindsUserGUIDs(cloudController, uaaClient)

	return services.NewSpaceStrategy(tokenLoader, spaceLoader, organizationLoader, findsUserGUIDs, enqueuer, m.V2Enqueuer())
}
		findsUserGUIDs = mocks.NewFindsUserGUIDs()
		findsUserGUIDs.UserGUIDsBelongingToSpaceCall.Returns.UserGUIDs = []string{"user-123", "user-456"}

		spaceLoader = mocks.NewSpaceLoader()
		spaceLoader.LoadCall.Returns.Space = cf.CloudControllerSpace{
			Name:             "production",
			GUID:             "space-001",
			OrganizationGUID: "org-001",
		}
		organizationLoader = mocks.NewOrganizationLoader()
		organizationLoader.LoadCall.Returns.Organization = cf.CloudControllerOrganization{
			Name: "the-org",
			GUID: "org-001",
		}
		strategy = services.NewSpaceStrategy(tokenLoader, spaceLoader, organizationLoader, findsUserGUIDs, v1Enqueuer, v2Enqueuer)
	})

	Describe("Dispatch", func() {
		Context("when the request is valid", func() {
			Context("and the dispatch JobType is v1", func() {
				It("calls v1Enqueuer.Enqueue with the correct arguments for a space", func() {
					_, err := strategy.Dispatch(services.Dispatch{
						GUID:       "space-001",
						Connection: conn,
						Message: services.DispatchMessage{
							To:      "*****@*****.**",
							ReplyTo: "*****@*****.**",
							Subject: "this is the subject",
							Text:    "Please reset your password by clicking on this link...",
							HTML: services.HTML{