Example #1
0
			Context("when the layer is retained", func() {
				BeforeEach(func() {
					fakeRetainer.IsHeldReturns(true)
				})

				It("should not remove the layer", func() {
					Expect(gc.Remove(layercake.ContainerID("child"))).To(Succeed())
					Expect(fakeCake.RemoveCallCount()).To(Equal(0))
				})
			})
		})

		Context("when removing fails", func() {
			It("returns an error", func() {
				fakeCake.RemoveReturns(errors.New("cake failure"))
				Expect(gc.Remove(layercake.ContainerID("whatever"))).To(MatchError("cake failure"))
			})
		})

		Context("when the layer has a parent", func() {
			BeforeEach(func() {
				child2parent[layercake.ContainerID("child")] = layercake.DockerImageID("parent")
			})

			Context("and the parent has no other children", func() {
				It("removes the layer, and its parent", func() {
					Expect(gc.Remove(layercake.ContainerID("child"))).To(Succeed())

					Expect(fakeCake.RemoveCallCount()).To(Equal(2))
					Expect(fakeCake.RemoveArgsForCall(0)).To(Equal(layercake.ContainerID("child")))
Example #2
0
	Context("when graphdriver fails to get layer path", func() {
		BeforeEach(func() {
			graphDriverErr = errors.New("graphdriver fail!")
		})

		It("returns the same error", func() {
			Expect(cleaner.Remove(layerId)).To(MatchError("graphdriver fail!"))
		})

		It("doesnt call the delegate", func() {
			Expect(fakeCake.RemoveCallCount()).To(Equal(0))
		})
	})

	It("delegates to the delegate", func() {
		Expect(cleaner.Remove(layerId)).To(Succeed())
		Expect(fakeCake.RemoveCallCount()).To(Equal(1))
	})

	Context("when the delegate fails", func() {
		BeforeEach(func() {
			fakeCake.RemoveReturns(errors.New("o no!"))
		})

		It("returns the same error", func() {
			Expect(cleaner.Remove(layerId)).To(MatchError("o no!"))
		})
	})
})