本文整理匯總了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)