本文整理匯總了Golang中code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake.GetReturns方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeCake.GetReturns方法的具體用法?Golang FakeCake.GetReturns怎麽用?Golang FakeCake.GetReturns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/garden-shed/layercake/fake_cake.FakeCake
的用法示例。
在下文中一共展示了FakeCake.GetReturns方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
var _ = Describe("Local", func() {
var (
fetcher *repository_fetcher.Local
fakeCake *fake_cake.FakeCake
defaultRootFSPath string
idProvider UnderscoreIDer
)
BeforeEach(func() {
fakeCake = new(fake_cake.FakeCake)
defaultRootFSPath = ""
idProvider = UnderscoreIDer{}
// default to not containing an image
fakeCake.GetReturns(nil, errors.New("no image"))
})
JustBeforeEach(func() {
fetcher = &repository_fetcher.Local{
Cake: fakeCake,
IDProvider: idProvider,
DefaultRootFSPath: defaultRootFSPath,
}
})
Describe("FetchID", func() {
It("delegates to the IDProvider", func() {
Expect(fetcher.FetchID(&url.URL{Path: "/something/something"})).To(Equal(layercake.DockerImageID("_something_something")))
})
})
示例2:
})
Context("when the threshold is exceeded", func() {
BeforeEach(func() {
fakeThreshold.ExceededReturns(true)
})
Describe("GC", func() {
Context("when there is a single leaf", func() {
BeforeEach(func() {
fakeCake.GetAllLeavesReturns([]layercake.ID{layercake.DockerImageID("child")}, nil)
size[layercake.DockerImageID("child2")] = 2048
})
It("should not remove it when it is used by a container", func() {
fakeCake.GetReturns(&image.Image{Container: "used-by-me"}, nil)
Expect(gc.GC(logger, fakeCake)).To(Succeed())
Expect(fakeCake.RemoveCallCount()).To(Equal(0))
})
Context("when the layer has no parents", func() {
BeforeEach(func() {
fakeCake.GetReturns(&image.Image{}, nil)
})
It("removes the layer", func() {
Expect(gc.GC(logger, fakeCake)).To(Succeed())
Expect(fakeCake.RemoveCallCount()).To(Equal(1))
Expect(fakeCake.RemoveArgsForCall(0)).To(Equal(layercake.DockerImageID("child")))
})
示例3:
_, err := cakeOrdinator.Metrics(logger, "something", "")
Expect(err).To(MatchError("rotten banana"))
})
})
})
Describe("Destroy", func() {
It("delegates removal", func() {
Expect(cakeOrdinator.Destroy(logger, "something", "rootfs")).To(Succeed())
Expect(fakeCake.RemoveCallCount()).To(Equal(1))
Expect(fakeCake.RemoveArgsForCall(0)).To(Equal(layercake.ContainerID("something")))
})
Context("when the layer is already destroyed", func() {
It("does not destroy again", func() {
fakeCake.GetReturns(nil, errors.New("cannae find it"))
Expect(cakeOrdinator.Destroy(logger, "something", "rootfs")).To(Succeed())
Expect(fakeCake.RemoveCallCount()).To(Equal(0))
})
})
Context("when the graph can't retrieve information about the layer", func() {
BeforeEach(func() {
fakeCake.GetReturns(nil, errors.New("failed tae find it"))
})
It("skips destroy and logs the error instead", func() {
Expect(cakeOrdinator.Destroy(logger, "something", "rootfs")).To(Succeed())
Expect(logger.LogMessages()).To(ContainElement("test.layer-already-deleted-skipping"))
})
示例4:
. "github.com/onsi/gomega"
)
var _ = Describe("AUFSBaseSizer", func() {
Describe("BaseSize", func() {
var (
baseSizer *quota_manager.AUFSBaseSizer
fakeCake *fake_cake.FakeCake
logger lager.Logger
)
BeforeEach(func() {
logger = lagertest.NewTestLogger("test")
fakeCake = new(fake_cake.FakeCake)
fakeCake.GetReturns(nil, errors.New("no such image"))
baseSizer = quota_manager.NewAUFSBaseSizer(fakeCake)
})
It("asks for the size of the layer based on the base name of the rootfs path", func() {
baseSizer.BaseSize(logger, "/some/path/to/54321")
Expect(fakeCake.GetCallCount()).To(Equal(1))
Expect(fakeCake.GetArgsForCall(0)).To(Equal(layercake.DockerImageID("54321")))
})
Context("when the layer doesn't exist", func() {
It("returns an error", func() {
_, err := baseSizer.BaseSize(logger, "/i/dont/exist")
Expect(err).To(HaveOccurred())
})
示例5:
Expect(err).To(HaveOccurred())
Expect(fakeVolumeCreator.Created).To(BeEmpty())
})
})
})
Context("when the namespace parameter is true", func() {
Context("and the image has not been translated yet", func() {
var (
mountpoint string
envvars []string
)
JustBeforeEach(func() {
fakeCake.GetReturns(nil, errors.New("no image here"))
fakeCake.PathStub = func(id layercake.ID) (string, error) {
return "/mount/point/" + id.GraphID(), nil
}
fakeNamespacer.CacheKeyReturns("jam")
var err error
mountpoint, envvars, err = provider.Create(
lagertest.NewTestLogger("test"),
"some-id",
&repository_fetcher.Image{
ImageID: "some-image-id",
Env: []string{"env1=env1value", "env2=env2value"},
},
示例6:
})
})
Context("when the image ID is namespaced", func() {
It("should delegate to the cake but with an empty parent", func() {
cake.CreateReturns(testError)
Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))
Expect(cake.CreateCallCount()).To(Equal(1))
cid, iid, _ := cake.CreateArgsForCall(0)
Expect(cid).To(Equal(namespacedChildID))
Expect(iid.GraphID()).To(BeEmpty())
})
Context("when mounting child fails", func() {
It("should return the error", func() {
cake.GetReturns(nil, testError)
Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))
})
})
Context("when getting parent's path fails", func() {
BeforeEach(func() {
cake.PathReturns("", testError)
})
It("should return the error", func() {
Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))
})
It("should not unmount the parent", func() {
Expect(aufsCake.Create(namespacedChildID, parentID, "")).To(Equal(testError))