Ejemplo n.º 1
0
				}
			}

			return true, nil
		}

		fakeCake.RemoveStub = func(id layercake.ID) error {
			delete(child2parent, id)
			return nil
		}
	})

	Describe("Remove", func() {
		Context("when the layer has no parents", func() {
			BeforeEach(func() {
				fakeCake.GetReturns(&image.Image{}, nil)
			})

			It("removes the layer", func() {
				Expect(gc.Remove(layercake.ContainerID("child"))).To(Succeed())
				Expect(fakeCake.RemoveCallCount()).To(Equal(1))
				Expect(fakeCake.RemoveArgsForCall(0)).To(Equal(layercake.ContainerID("child")))
			})

			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())
Ejemplo n.º 2
0
	})
})

var _ = Describe("Local", func() {
	var fetcher *repository_fetcher.Local
	var fakeCake *fake_cake.FakeCake
	var defaultRootFSPath string
	var logger lager.Logger

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("local")
		fakeCake = new(fake_cake.FakeCake)
		defaultRootFSPath = ""

		// default to not containing an image
		fakeCake.GetReturns(nil, errors.New("no image"))
	})

	JustBeforeEach(func() {
		fetcher = &repository_fetcher.Local{
			Cake:              fakeCake,
			IDProvider:        UnderscoreIDer{},
			DefaultRootFSPath: defaultRootFSPath,
		}
	})

	Context("when the image already exists in the graph", func() {
		It("returns the image id", func() {
			fakeCake.GetReturns(&image.Image{}, nil)

			rootFSPath, err := ioutil.TempDir("", "testdir")
Ejemplo n.º 3
0
			Endpoint:   endpoint,
			Logger:     logger,
			Path:       "some-repo",
			RemotePath: "some-repo",
			Tag:        "some-tag",
			MaxSize:    math.MaxInt64,
		}

		retainer = new(fake_retainer.FakeRetainer)
		fetcher = &RemoteV2Fetcher{
			Cake:      cake,
			Retainer:  retainer,
			GraphLock: lock,
		}

		cake.GetReturns(nil, errors.New("no image"))
	})

	It("retains the layers before getting them, to ensure they are not deleted after we decide to use cache", func() {
		setupSuccessfulV2Fetch(server, false)

		retained := make(map[layercake.ID]bool)
		cake.GetStub = func(id layercake.ID) (*image.Image, error) {
			Expect(retained).To(HaveKey(id))
			return nil, errors.New("no layer")
		}

		retainer.RetainStub = func(id layercake.ID) {
			retained[id] = true
		}
				))

				Expect(mountpoint).To(Equal("/some/graph/driver/mount/point"))
				Expect(envvars).To(Equal(
					process.Env{
						"env1": "env1Value",
						"env2": "env2Value",
					},
				))
			})
		})

		Context("when the namespace parameter is true", func() {
			Context("and the image has not been translated yet", func() {
				BeforeEach(func() {
					fakeCake.GetReturns(nil, errors.New("no image here"))
				})

				It("fetches it, namespaces it, and creates a graph entry with it as the parent", func() {
					fakeRepositoryFetcher.FetchResult = "some-image-id"
					fakeCake.PathStub = func(id layercake.ID) (string, error) {
						return "/mount/point/" + id.GraphID(), nil
					}

					fakeNamespacer.CacheKeyReturns("jam")

					mountpoint, envvars, err := provider.ProvideRootFS(
						logger,
						"some-id",
						parseURL("docker:///some-repository-name"),
						true,
Ejemplo n.º 5
0
			Session:  session,
			Endpoint: endpoint,
			Logger:   logger,
			Path:     "some-repo",
			Tag:      "some-tag",
			MaxSize:  99999,
		}

		retainer = new(fake_retainer.FakeRetainer)
		fetcher = &RemoteV1Fetcher{
			Cake:      cake,
			Retainer:  retainer,
			GraphLock: lock,
		}

		cake.GetReturns(&image.Image{}, nil)
	})

	It("retains all the layers before starting", func() {
		setupSuccessfulFetch(endpoint1Server)

		retained := make(map[layercake.ID]bool)
		cake.GetStub = func(id layercake.ID) (*image.Image, error) {
			Expect(retained).To(HaveKey(layercake.DockerImageID("layer-1")))
			Expect(retained).To(HaveKey(layercake.DockerImageID("layer-2")))
			Expect(retained).To(HaveKey(layercake.DockerImageID("layer-3")))
			return nil, errors.New("no layer")
		}

		retainer.RetainStub = func(id layercake.ID) {
			retained[id] = true