本文整理汇总了Golang中code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake.GetStub方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeCake.GetStub方法的具体用法?Golang FakeCake.GetStub怎么用?Golang FakeCake.GetStub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake
的用法示例。
在下文中一共展示了FakeCake.GetStub方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
)
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
示例2:
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))
})
})
})
})
})
示例3:
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()))
})
示例4:
})
})
})
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{
示例5:
}
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)