use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_onlyPlatforms() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("target-arch", "target-os")).thenReturn(Arrays.asList("sha256:target-digest"));
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setContainerUser("target-user");
ManifestAndConfigTemplate targetManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:target-digest");
ManifestAndConfigTemplate unrelatedManifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:unrelated-digest");
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(unrelatedManifestAndConfig, targetManifestAndConfig, unrelatedManifestAndConfig));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("target-arch", "target-os")));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals("target-user", images.get(0).getUser());
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestCached.
@Test
public void testGetCachedBaseImages_v22ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setArchitecture("slim arch");
containerConfigJson.setOs("fat system");
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals("slim arch", images.get(0).getArchitecture());
Assert.assertEquals("fat system", images.get(0).getOs());
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v22ManifestListCached_partialMatches.
@Test
public void testGetCachedBaseImages_v22ManifestListCached_partialMatches() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
V22ManifestListTemplate manifestList = Mockito.mock(V22ManifestListTemplate.class);
Mockito.when(manifestList.getDigestsForPlatform("arch1", "os1")).thenReturn(Arrays.asList("sha256:digest1"));
Mockito.when(manifestList.getDigestsForPlatform("arch2", "os2")).thenReturn(Arrays.asList("sha256:digest2"));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(manifestList, Arrays.asList(new ManifestAndConfigTemplate(new V22ManifestTemplate(), new ContainerConfigurationTemplate(), "sha256:digest1")));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
Mockito.when(containerConfig.getPlatforms()).thenReturn(ImmutableSet.of(new Platform("arch1", "os1"), new Platform("arch2", "os2")));
Assert.assertEquals(Arrays.asList(), pullBaseImageStep.getCachedBaseImages());
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testGetCachedBaseImages_v21ManifestCached.
@Test
public void testGetCachedBaseImages_v21ManifestCached() throws InvalidImageReferenceException, IOException, CacheCorruptedException, UnlistedPlatformInManifestListException, BadContainerConfigurationFormatException, LayerCountMismatchException, DigestException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(buildContext.getBaseImageConfiguration()).thenReturn(ImageConfiguration.builder(imageReference).build());
DescriptorDigest layerDigest = DescriptorDigest.fromHash("1111111111111111111111111111111111111111111111111111111111111111");
V21ManifestTemplate v21Manifest = Mockito.mock(V21ManifestTemplate.class);
Mockito.when(v21Manifest.getLayerDigests()).thenReturn(Arrays.asList(layerDigest));
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(new ManifestAndConfigTemplate(v21Manifest, null)));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
List<Image> images = pullBaseImageStep.getCachedBaseImages();
Assert.assertEquals(1, images.size());
Assert.assertEquals(1, images.get(0).getLayers().size());
Assert.assertEquals("1111111111111111111111111111111111111111111111111111111111111111", images.get(0).getLayers().get(0).getBlobDescriptor().getDigest().getHash());
}
use of com.google.cloud.tools.jib.image.json.ManifestAndConfigTemplate in project jib by GoogleContainerTools.
the class PullBaseImageStepTest method testCall_offlineMode_cached.
@Test
public void testCall_offlineMode_cached() throws LayerPropertyNotFoundException, RegistryException, LayerCountMismatchException, BadContainerConfigurationFormatException, CacheCorruptedException, CredentialRetrievalException, InvalidImageReferenceException, IOException {
ImageReference imageReference = ImageReference.parse("cat");
Mockito.when(imageConfiguration.getImage()).thenReturn(imageReference);
Mockito.when(buildContext.isOffline()).thenReturn(true);
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setArchitecture("slim arch");
containerConfigJson.setOs("fat system");
ManifestAndConfigTemplate manifestAndConfig = new ManifestAndConfigTemplate(new V22ManifestTemplate(), containerConfigJson, "sha256:digest");
ImageMetadataTemplate imageMetadata = new ImageMetadataTemplate(null, Arrays.asList(manifestAndConfig));
Mockito.when(cache.retrieveMetadata(imageReference)).thenReturn(Optional.of(imageMetadata));
ImagesAndRegistryClient result = pullBaseImageStep.call();
Assert.assertEquals("fat system", result.images.get(0).getOs());
Assert.assertNull(result.registryClient);
Mockito.verify(buildContext, Mockito.never()).newBaseImageRegistryClientFactory();
}
Aggregations