Search in sources :

Example 21 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testCall_allMirrorsFail.

@Test
public void testCall_allMirrorsFail() throws InvalidImageReferenceException, IOException, RegistryException, LayerPropertyNotFoundException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException {
    Mockito.when(imageConfiguration.getImage()).thenReturn(ImageReference.parse("registry/repo"));
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("registry", "quay.io", "registry", "gcr.io"));
    Mockito.when(buildContext.newBaseImageRegistryClientFactory(Mockito.any())).thenReturn(registryClientFactory);
    Mockito.when(registryClient.pullManifest(Mockito.any())).thenThrow(new RegistryException("not found"));
    RegistryClient.Factory dockerHubRegistryClientFactory = setUpWorkingRegistryClientFactory();
    Mockito.when(buildContext.newBaseImageRegistryClientFactory()).thenReturn(dockerHubRegistryClientFactory);
    ImagesAndRegistryClient result = pullBaseImageStep.call();
    Assert.assertEquals(dockerHubRegistryClientFactory.newRegistryClient(), result.registryClient);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror quay.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror quay.io: not found"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror gcr.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror gcr.io: not found"));
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) RegistryClient(com.google.cloud.tools.jib.registry.RegistryClient) RegistryException(com.google.cloud.tools.jib.api.RegistryException) Test(org.junit.Test)

Example 22 with ImagesAndRegistryClient

use of com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient in project jib by GoogleContainerTools.

the class PullBaseImageStepTest method testTryMirrors_mirrorIoError.

@Test
public void testTryMirrors_mirrorIoError() throws LayerCountMismatchException, BadContainerConfigurationFormatException, IOException, RegistryException {
    Mockito.when(imageConfiguration.getImageRegistry()).thenReturn("registry");
    Mockito.when(buildContext.getRegistryMirrors()).thenReturn(ImmutableListMultimap.of("registry", "gcr.io"));
    Mockito.when(buildContext.newBaseImageRegistryClientFactory("gcr.io")).thenReturn(registryClientFactory);
    Mockito.when(registryClient.pullManifest(Mockito.any())).thenThrow(new IOException("test exception"));
    Optional<ImagesAndRegistryClient> result = pullBaseImageStep.tryMirrors(buildContext, progressDispatcherFactory);
    Assert.assertEquals(Optional.empty(), result);
    InOrder inOrder = Mockito.inOrder(eventHandlers);
    inOrder.verify(eventHandlers).dispatch(LogEvent.info("trying mirror gcr.io for the base image"));
    inOrder.verify(eventHandlers).dispatch(LogEvent.debug("failed to get manifest from mirror gcr.io: test exception"));
}
Also used : InOrder(org.mockito.InOrder) ImagesAndRegistryClient(com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ImagesAndRegistryClient (com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.ImagesAndRegistryClient)22 Test (org.junit.Test)18 RegistryClient (com.google.cloud.tools.jib.registry.RegistryClient)8 InOrder (org.mockito.InOrder)8 ImageReference (com.google.cloud.tools.jib.api.ImageReference)6 RegistryException (com.google.cloud.tools.jib.api.RegistryException)6 Image (com.google.cloud.tools.jib.image.Image)6 IOException (java.io.IOException)6 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)4 ProgressEventDispatcher (com.google.cloud.tools.jib.builder.ProgressEventDispatcher)4 TimerEventDispatcher (com.google.cloud.tools.jib.builder.TimerEventDispatcher)4 EventHandlers (com.google.cloud.tools.jib.event.EventHandlers)4 ContainerConfigurationTemplate (com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate)4 ImageMetadataTemplate (com.google.cloud.tools.jib.image.json.ImageMetadataTemplate)4 ManifestAndConfigTemplate (com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate)4 V22ManifestTemplate (com.google.cloud.tools.jib.image.json.V22ManifestTemplate)4 Credential (com.google.cloud.tools.jib.api.Credential)2 DescriptorDigest (com.google.cloud.tools.jib.api.DescriptorDigest)2 RegistryUnauthorizedException (com.google.cloud.tools.jib.api.RegistryUnauthorizedException)2 DigestOnlyLayer (com.google.cloud.tools.jib.image.DigestOnlyLayer)2