repoURL, err = url.Parse("http://fake-registry-1.docker.io/") Expect(err).NotTo(HaveOccurred()) logger = lagertest.NewTestLogger("test") retryable = repository_fetcher.Retryable{ RepositoryFetcher: fakeRemoteFetcher, Logger: logger, } }) Describe("Fetch failures", func() { Context("when fetching fails twice", func() { BeforeEach(func() { fakeRemoteFetcher.FetchStub = func(u *url.URL, diskQuota int64) (*repository_fetcher.Image, error) { if fakeRemoteFetcher.FetchCallCount() <= 2 { return nil, errors.New("error-talking-to-remote-repo") } else { return nil, nil } } _, err := retryable.Fetch(repoURL, 0) Expect(err).NotTo(HaveOccurred()) }) It("suceeds on third attempt", func() { Expect(fakeRemoteFetcher.FetchCallCount()).To(Equal(3)) }) It("logs failing attempts", func() {
) BeforeEach(func() { fakeLocalFetcher = new(fakes.FakeRepositoryFetcher) fakeRemoteFetcher = new(fakes.FakeRepositoryFetcher) factory = &CompositeFetcher{ LocalFetcher: fakeLocalFetcher, RemoteFetcher: fakeRemoteFetcher, } }) Context("when the URL does not contain a scheme", func() { It("delegates .Fetch to the local fetcher", func() { factory.Fetch(&url.URL{Path: "cake"}, 24) Expect(fakeLocalFetcher.FetchCallCount()).To(Equal(1)) Expect(fakeRemoteFetcher.FetchCallCount()).To(Equal(0)) }) It("delegates .FetchID to the local fetcher", func() { factory.FetchID(&url.URL{Path: "cake"}) Expect(fakeLocalFetcher.FetchIDCallCount()).To(Equal(1)) Expect(fakeRemoteFetcher.FetchIDCallCount()).To(Equal(0)) }) }) Context("when the scheme is docker://", func() { It("delegates .Fetch to the remote fetcher", func() { factory.Fetch(&url.URL{Scheme: "docker", Path: "cake"}, 24) Expect(fakeRemoteFetcher.FetchCallCount()).To(Equal(1)) Expect(fakeLocalFetcher.FetchCallCount()).To(Equal(0))