}) }) }) Describe("Property", func() { BeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/containers/containerhandle/properties/key:val"), ghttp.RespondWith(200, `"a value"`), ), ) }) It("makes a call out to an external service", func() { property, err := container.Property("key:val") Expect(err).NotTo(HaveOccurred()) Expect(server.ReceivedRequests()).Should(HaveLen(1)) Expect(property).Should(Equal("a value")) }) }) Describe("Stop Container", func() { Context("container exists", func() { BeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/containers/containerhandle/stop"), ghttp.RespondWith(200, ""), ),
Expect(propertyManager.AllCallCount()).To(Equal(1)) handle := propertyManager.AllArgsForCall(0) Expect(handle).To(Equal("some-handle")) }) It("delegates to the property manager for SetProperty", func() { container.SetProperty("name", "value") Expect(propertyManager.SetCallCount()).To(Equal(1)) handle, prop, val := propertyManager.SetArgsForCall(0) Expect(handle).To(Equal("some-handle")) Expect(prop).To(Equal("name")) Expect(val).To(Equal("value")) }) It("delegates to the property manager for Property", func() { container.Property("name") Expect(propertyManager.GetCallCount()).To(Equal(1)) handle, name := propertyManager.GetArgsForCall(0) Expect(handle).To(Equal("some-handle")) Expect(name).To(Equal("name")) }) It("delegates to the property manager for RemoveProperty", func() { container.RemoveProperty("name") Expect(propertyManager.RemoveCallCount()).To(Equal(1)) handle, name := propertyManager.RemoveArgsForCall(0) Expect(handle).To(Equal("some-handle")) Expect(name).To(Equal("name")) }) }) })
}) Describe("getting container properties without getting info", func() { It("can list properties", func() { err := container.SetProperty("bar", "baz") value, err := container.Properties() Expect(err).ToNot(HaveOccurred()) Expect(value).To(HaveKeyWithValue("foo", "bar")) Expect(value).To(HaveKeyWithValue("bar", "baz")) }) }) Describe("updating container properties", func() { It("can CRUD", func() { value, err := container.Property("foo") Expect(err).ToNot(HaveOccurred()) Expect(value).To(Equal("bar")) err = container.SetProperty("foo", "baz") Expect(err).ToNot(HaveOccurred()) err = container.RemoveProperty("a") Expect(err).ToNot(HaveOccurred()) info, err := container.Info() Expect(err).ToNot(HaveOccurred()) Expect(info.Properties).To(Equal(garden.Properties{ "foo": "baz", }))
}) }) }) Describe("Property", func() { propertyName := "propertyName" propertyValue := "propertyValue" Context("when getting property succeeds", func() { BeforeEach(func() { fakeConnection.PropertyReturns(propertyValue, nil) }) It("returns the value", func() { result, err := container.Property(propertyName) Ω(err).ShouldNot(HaveOccurred()) Ω(result).Should(Equal(propertyValue)) }) }) Context("when getting property fails", func() { disaster := errors.New("oh no!") BeforeEach(func() { fakeConnection.PropertyReturns("", disaster) }) It("returns the error", func() { _, err := container.Property(propertyName) Ω(err).Should(Equal(disaster))
It("can set a single property", func() { err := container.SetProperty("someothername", "someothervalue") Expect(err).NotTo(HaveOccurred()) properties, err := container.Properties() Expect(err).NotTo(HaveOccurred()) Expect(properties).To(HaveKeyWithValue("somename", "somevalue")) Expect(properties).To(HaveKeyWithValue("someothername", "someothervalue")) }) It("can get a single property", func() { err := container.SetProperty("bing", "bong") Expect(err).NotTo(HaveOccurred()) value, err := container.Property("bing") Expect(err).NotTo(HaveOccurred()) Expect(value).To(Equal("bong")) }) It("can remove a single property", func() { err := container.SetProperty("bing", "bong") Expect(err).NotTo(HaveOccurred()) err = container.RemoveProperty("bing") Expect(err).NotTo(HaveOccurred()) _, err = container.Property("bing") Expect(err).To(HaveOccurred()) })