Exemplo n.º 1
0
			Eventually(fakeDB.SetEncryptionKeyLabelCallCount).Should(Equal(1))
			_, newLabel := fakeDB.SetEncryptionKeyLabelArgsForCall(0)
			Expect(newLabel).To(Equal("label"))
		})
	})

	Context("when encrypting fails", func() {
		BeforeEach(func() {
			fakeDB.PerformEncryptionReturns(errors.New("something is broken"))
		})

		It("does not fail and logs the error", func() {
			Eventually(encryptorProcess.Ready()).Should(BeClosed())
			Eventually(logger.LogMessages).Should(ContainElement("test.encryptor.encryption-finished"))

			Expect(logger.LogMessages()).To(ContainElement("test.encryptor.encryption-failed"))
		})

		It("does not change the key in the db", func() {
			Consistently(fakeDB.SetEncryptionKeyLabelCallCount).Should(Equal(0))
		})
	})

	Context("when fetching the current encryption key fails", func() {
		BeforeEach(func() {
			fakeDB.EncryptionKeyLabelReturns("", errors.New("can't fetch"))
		})

		It("fails early", func() {
			var err error
			Eventually(encryptorProcess.Wait()).Should(Receive(&err))
			Expect(err).ToNot(HaveOccurred())

			info, err := container.Info()
			Expect(err).ToNot(HaveOccurred())
			Expect(info.MappedPorts).To(Equal([]garden.PortMapping{
				{HostPort: 1234, ContainerPort: 5678},
				{HostPort: 1235, ContainerPort: 5679},
			}))

		})

		It("should log before and after", func() {
			_, err := container.Info()
			Expect(err).ToNot(HaveOccurred())

			Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("info-starting")))
			Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("info-ended")))
		})

		Context("with running processes", func() {
			JustBeforeEach(func() {
				p1 := new(wfakes.FakeProcess)
				p1.IDReturns("1")

				p2 := new(wfakes.FakeProcess)
				p2.IDReturns("2")

				p3 := new(wfakes.FakeProcess)
				p3.IDReturns("3")

				fakeProcessTracker.ActiveProcessesReturns([]garden.Process{p1, p2, p3})
			credentialsGenerator.GenerateReturns(rabbitbroker.Credentials{
				Username: "******",
				Password: "******",
			})
		})

		It("returns no error", func() {
			_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(err).NotTo(HaveOccurred())
		})

		It("logs a message stating that it is provisioning", func() {
			_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(err).NotTo(HaveOccurred())
			Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("Asked to provision a service: my-service-id")))
		})

		It("returns a dashboard url", func() {
			provisionedSpec, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(err).NotTo(HaveOccurred())
			Expect(provisionedSpec.DashboardURL).To(MatchRegexp(`https://%s/#/login/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]+`, config.Rabbitmq.ManagementDomain))
		})

		It("checks whether the host exist", func() {
			_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
			Expect(client.GetVhostCallCount()).To(Equal(1))
			Expect(client.GetVhostArgsForCall(0)).To(Equal("my-service-id"))
			Expect(err).NotTo(HaveOccurred())
		})
Exemplo n.º 4
0
					Properties: garden.Properties{"a": "b"},
				})
				Expect(err).ToNot(HaveOccurred())

				_, err = linuxBackend.Create(garden.ContainerSpec{
					Handle:     "container-2",
					Properties: garden.Properties{"a": "b"},
				})
				Expect(err).ToNot(HaveOccurred())

				_, err = linuxBackend.Containers(
					garden.Properties{"a": "b"},
				)
				Expect(err).ToNot(HaveOccurred())

				Expect(logger.LogMessages()).To(ConsistOf("test.backend.containers.started", "test.backend.containers.matched", "test.backend.containers.matched", "test.backend.containers.ending"))

				logs := logger.Logs()
				Expect(logs[3].Data["handles"]).To(ConsistOf("container-1", "container-2"))
			})

			It("should log the entry and exit when there are no containers", func() {
				_, err := linuxBackend.Containers(
					garden.Properties{"a": "b", "e": "f"},
				)
				Expect(err).ToNot(HaveOccurred())

				Expect(logger.LogMessages()).To(ConsistOf("test.backend.containers.started", "test.backend.containers.ending"))
			})
		})
	})