本文整理汇总了Golang中code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake.RegisterStub方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeCake.RegisterStub方法的具体用法?Golang FakeCake.RegisterStub怎么用?Golang FakeCake.RegisterStub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake
的用法示例。
在下文中一共展示了FakeCake.RegisterStub方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
var tmpDir string
BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir("", "tmp-dir")
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
os.RemoveAll(tmpDir)
})
It("registers the image in the graph", func() {
var registeredImage *image.Image
fakeCake.RegisterStub = func(image *image.Image, layer archive.ArchiveReader) error {
registeredImage = image
return nil
}
dirPath := path.Join(tmpDir, "foo/bar/baz")
err := os.MkdirAll(dirPath, 0700)
Expect(err).NotTo(HaveOccurred())
_, err = fetcher.Fetch(&url.URL{Path: dirPath}, 0)
Expect(err).NotTo(HaveOccurred())
Expect(registeredImage).NotTo(BeNil())
Expect(registeredImage.ID).To(HaveSuffix("foo_bar_baz"))
})
It("registers the image with the correct layer data", func() {
fakeCake.RegisterStub = func(image *image.Image, layer archive.ArchiveReader) error {
示例2:
It("should verify the image against its digest", func() {
remote.Fetch(parseURL("docker:///foo#some-tag"), 67)
_, reader := fakeCake.RegisterArgsForCall(0)
Expect(reader).To(BeAssignableToTypeOf(&verified{}))
_, digest1 := fakeVerifier.VerifyArgsForCall(0)
_, digest2 := fakeVerifier.VerifyArgsForCall(1)
Expect(string(digest1)).To(Equal("abc-def"))
Expect(string(digest2)).To(Equal("ghj-klm"))
})
It("should close the verified image reader after using it", func() {
var registeredBlob *verified
fakeCake.RegisterStub = func(img *image.Image, blob archive.ArchiveReader) error {
Expect(blob).To(BeAssignableToTypeOf(&verified{}))
Expect(blob.(*verified).closed).To(BeFalse())
registeredBlob = blob.(*verified)
return nil
}
remote.Fetch(parseURL("docker:///foo#some-tag"), 67)
Expect(registeredBlob.closed).To(BeTrue())
})
Context("when the layer does not match its digest", func() {
JustBeforeEach(func() {
fakeVerifier.VerifyReturns(nil, errors.New("boom"))
})
It("returns an error", func() {
_, err := remote.Fetch(parseURL("docker:///foo#some-tag"), 67)
Expect(err).To(MatchError("boom"))