) BeforeEach(func() { fakeThreshold = new(fakes.FakeThreshold) logger = lagertest.NewTestLogger("test") retainer = cleaner.NewRetainer() fakeCake = new(fake_cake.FakeCake) fakeCake.GetStub = func(id layercake.ID) (*image.Image, error) { if parent, ok := child2parent[id]; ok { return &image.Image{ ID: id.GraphID(), Parent: parent.GraphID(), Size: size[id], }, nil } return &image.Image{ Size: size[id], }, nil } fakeCake.IsLeafStub = func(id layercake.ID) (bool, error) { for _, p := range child2parent { if p == id { return false, nil } } return true, nil
fakeCake.GetReturns(&image.Image{ Size: 1234, }, nil) size, err := baseSizer.BaseSize(logger, "/i/do/exist") Expect(err).NotTo(HaveOccurred()) Expect(size).To(BeNumerically("==", 1234)) }) }) Context("and has parents", func() { It("returns the total size of all the parents", func() { imgs := map[string]*image.Image{ "child": &image.Image{Parent: "parent1", Size: 1234}, "parent1": &image.Image{Parent: "parent2", Size: 456}, "parent2": &image.Image{Size: 789}, } fakeCake.GetStub = func(id layercake.ID) (*image.Image, error) { return imgs[id.GraphID()], nil } size, err := baseSizer.BaseSize(logger, "/i/have/parent/layers/child") Expect(err).NotTo(HaveOccurred()) Expect(size).To(BeNumerically("==", 1234+456+789)) }) }) }) }) })
isLeaf, err := aufsCake.IsLeaf(parentID) Expect(err).NotTo(HaveOccurred()) Expect(isLeaf).To(BeFalse()) }) It("keeps child-parent relationship information", func() { cake.GetStub = func(id layercake.ID) (*image.Image, error) { if id != parentID && id != childID && id != namespacedChildID && id != otherNamespacedChildID { return nil, testError } img := &image.Image{ ID: id.GraphID(), } if id == childID { img.Parent = parentID.GraphID() } return img, nil } Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Succeed()) img, err := aufsCake.Get(namespacedChildID) Expect(err).NotTo(HaveOccurred()) Expect(img.Parent).To(Equal(parentID.GraphID())) })
}) }) }) Context("and the image has already been translated", func() { BeforeEach(func() { fakeCake.PathStub = func(id layercake.ID) (string, error) { return "/mount/point/" + id.GraphID(), nil } fakeNamespacer.CacheKeyReturns("sandwich") fakeCake.GetStub = func(id layercake.ID) (*image.Image, error) { if id == (layercake.NamespacedID(layercake.DockerImageID("some-image-id"), "sandwich")) { return &image.Image{}, nil } return nil, errors.New("hello") } }) It("reuses the translated layer", func() { mountpoint, envvars, err := provider.Create( lagertest.NewTestLogger("test"), "some-id", &repository_fetcher.Image{ ImageID: "some-image-id", Env: []string{"env1=env1value", "env2=env2value"}, }, rootfs_provider.Spec{
} fakeConn.GetBlobReaderStub = func(_ lager.Logger, digest digest.Digest) (io.Reader, error) { return bytes.NewReader([]byte(blobs[digest])), nil } fakeDialer = new(fakes.FakeDialer) fakeDialer.DialStub = func(_ lager.Logger, host, repo string) (distclient.Conn, error) { return fakeConn, nil } fakeCake = new(fake_cake.FakeCake) fakeCake.GetStub = func(id layercake.ID) (*image.Image, error) { if _, ok := existingLayers[id.GraphID()]; ok { return &image.Image{Size: 33}, nil } return nil, errors.New("doesnt exist") } fakeVerifier = new(fakes.FakeVerifier) fakeVerifier.VerifyStub = func(r io.Reader, d digest.Digest) (io.ReadCloser, error) { return &verified{Reader: r}, nil } remote = repository_fetcher.NewRemote(lagertest.NewTestLogger("test"), defaultDockerRegistryHost, fakeCake, fakeDialer, fakeVerifier) }) Context("when the URL has a host", func() { It("dials that host", func() { _, err := remote.Fetch(parseURL("docker://some-host/some/repo#some-tag"), 1234)