use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ImageToJsonTranslatorTest method setUp.
private void setUp(Class<? extends BuildableManifestTemplate> imageFormat) throws DigestException, LayerPropertyNotFoundException {
Image.Builder testImageBuilder = Image.builder(imageFormat).setCreated(Instant.ofEpochSecond(20)).setArchitecture("wasm").setOs("js").addEnvironmentVariable("VAR1", "VAL1").addEnvironmentVariable("VAR2", "VAL2").setEntrypoint(Arrays.asList("some", "entrypoint", "command")).setProgramArguments(Arrays.asList("arg1", "arg2")).setHealthCheck(DockerHealthCheck.fromCommand(ImmutableList.of("CMD-SHELL", "/checkhealth")).setInterval(Duration.ofSeconds(3)).setTimeout(Duration.ofSeconds(1)).setStartPeriod(Duration.ofSeconds(2)).setRetries(3).build()).addExposedPorts(ImmutableSet.of(Port.tcp(1000), Port.tcp(2000), Port.udp(3000))).addVolumes(ImmutableSet.of(AbsoluteUnixPath.get("/var/job-result-data"), AbsoluteUnixPath.get("/var/log/my-app-logs"))).addLabels(ImmutableMap.of("key1", "value1", "key2", "value2")).setWorkingDirectory("/some/workspace").setUser("tomcat");
DescriptorDigest fakeDigest = DescriptorDigest.fromDigest("sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");
testImageBuilder.addLayer(new Layer() {
@Override
public Blob getBlob() throws LayerPropertyNotFoundException {
return Blobs.from("ignored");
}
@Override
public BlobDescriptor getBlobDescriptor() throws LayerPropertyNotFoundException {
return new BlobDescriptor(1000, fakeDigest);
}
@Override
public DescriptorDigest getDiffId() throws LayerPropertyNotFoundException {
return fakeDigest;
}
});
testImageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(Instant.EPOCH).setAuthor("Bazel").setCreatedBy("bazel build ...").setEmptyLayer(true).build());
testImageBuilder.addHistory(HistoryEntry.builder().setCreationTimestamp(Instant.ofEpochSecond(20)).setAuthor("Jib").setCreatedBy("jib").build());
imageToJsonTranslator = new ImageToJsonTranslator(testImageBuilder.build());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ManifestPullerTest method testHandleResponse_v22ManifestListFromParentType.
@Test
public void testHandleResponse_v22ManifestListFromParentType() throws URISyntaxException, IOException, UnknownManifestFormatException {
Path v22ManifestListFile = Paths.get(Resources.getResource("core/json/v22manifest_list.json").toURI());
InputStream v22ManifestList = new ByteArrayInputStream(Files.readAllBytes(v22ManifestListFile));
DescriptorDigest expectedDigest = Digests.computeDigest(v22ManifestList).getDigest();
v22ManifestList.reset();
Mockito.when(mockResponse.getBody()).thenReturn(v22ManifestList);
ManifestAndDigest<?> manifestAndDigest = new ManifestPuller<>(fakeRegistryEndpointRequestProperties, "test-image-tag", ManifestTemplate.class).handleResponse(mockResponse);
ManifestTemplate manifestTemplate = manifestAndDigest.getManifest();
MatcherAssert.assertThat(manifestTemplate, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
Assert.assertTrue(((V22ManifestListTemplate) manifestTemplate).getManifests().size() > 0);
Assert.assertEquals(expectedDigest, manifestAndDigest.getDigest());
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ManifestPusherTest method testHandleResponse_noDigest.
@Test
public void testHandleResponse_noDigest() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Collections.emptyList());
Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received none"));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ManifestPusherTest method testHandleResponse_multipleDigests.
@Test
public void testHandleResponse_multipleDigests() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Arrays.asList("too", "many"));
Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: too, many"));
}
use of com.google.cloud.tools.jib.api.DescriptorDigest in project jib by GoogleContainerTools.
the class ManifestPusherTest method testHandleResponse_invalidDigest.
@Test
public void testHandleResponse_invalidDigest() throws IOException {
DescriptorDigest expectedDigest = Digests.computeJsonDigest(fakeManifestTemplate);
Mockito.when(mockResponse.getHeader("Docker-Content-Digest")).thenReturn(Collections.singletonList("not valid"));
Assert.assertEquals(expectedDigest, testManifestPusher.handleResponse(mockResponse));
Mockito.verify(mockEventHandlers).dispatch(LogEvent.warn("Expected image digest " + expectedDigest + ", but received: not valid"));
}
Aggregations