use of io.fabric8.maven.docker.model.ImageArchiveManifestEntry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method findByRepoTagSuccessfully.
@Test
public void findByRepoTagSuccessfully() {
ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
ImageArchiveManifestEntry found = ImageArchiveUtil.findEntryByRepoTag("test/image:latest", nonEmpty);
Assert.assertNotNull(found);
Assert.assertTrue(found.getRepoTags().contains("test/image:latest"));
}
use of io.fabric8.maven.docker.model.ImageArchiveManifestEntry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method mapEntriesByIdSuccessfully.
@Test
public void mapEntriesByIdSuccessfully() {
ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
Map<String, ImageArchiveManifestEntry> entries = ImageArchiveUtil.mapEntriesById(nonEmpty.getEntries());
Assert.assertNotNull(entries);
Assert.assertEquals(1, entries.size());
Assert.assertNotNull(entries.get("image-id-sha256"));
Assert.assertTrue(entries.get("image-id-sha256").getRepoTags().contains("test/image:latest"));
}
use of io.fabric8.maven.docker.model.ImageArchiveManifestEntry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method findByRepoTagPatternSuccessfully.
@Test
public void findByRepoTagPatternSuccessfully() {
ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
Pair<String, ImageArchiveManifestEntry> found;
// Complete match
found = ImageArchiveUtil.findEntryByRepoTagPattern("test/image:latest", nonEmpty);
Assert.assertNotNull(found);
Assert.assertEquals("test/image:latest", found.getLeft());
Assert.assertNotNull(found.getRight());
Assert.assertTrue(found.getRight().getRepoTags().contains("test/image:latest"));
// Unanchored match
found = ImageArchiveUtil.findEntryByRepoTagPattern("test/image", nonEmpty);
Assert.assertNotNull(found);
Assert.assertEquals("test/image:latest", found.getLeft());
Assert.assertNotNull(found.getRight());
Assert.assertTrue(found.getRight().getRepoTags().contains("test/image:latest"));
// Initial anchor
found = ImageArchiveUtil.findEntryByRepoTagPattern("^test/image", nonEmpty);
Assert.assertNotNull(found);
Assert.assertEquals("test/image:latest", found.getLeft());
Assert.assertNotNull(found.getRight());
Assert.assertTrue(found.getRight().getRepoTags().contains("test/image:latest"));
}
use of io.fabric8.maven.docker.model.ImageArchiveManifestEntry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method findEntriesByRepoTagPatternEmptyManifest.
@Test
public void findEntriesByRepoTagPatternEmptyManifest() {
ImageArchiveManifest empty = new ImageArchiveManifestAdapter(new JsonArray());
Map<String, ImageArchiveManifestEntry> entries;
entries = ImageArchiveUtil.findEntriesByRepoTagPattern((String) null, null);
Assert.assertNotNull(entries);
Assert.assertTrue(entries.isEmpty());
entries = ImageArchiveUtil.findEntriesByRepoTagPattern(".*", null);
Assert.assertNotNull(entries);
Assert.assertTrue(entries.isEmpty());
entries = ImageArchiveUtil.findEntriesByRepoTagPattern((String) null, empty);
Assert.assertNotNull(entries);
Assert.assertTrue(entries.isEmpty());
entries = ImageArchiveUtil.findEntriesByRepoTagPattern(".*", empty);
Assert.assertNotNull(entries);
Assert.assertTrue(entries.isEmpty());
}
use of io.fabric8.maven.docker.model.ImageArchiveManifestEntry in project docker-maven-plugin by fabric8io.
the class ImageArchiveUtilTest method readValidArchive.
@Test
public void readValidArchive() throws IOException {
final byte[] entryData = new Gson().toJson(createBasicManifestJson()).getBytes(StandardCharsets.UTF_8);
final byte[] relatedData = new Gson().toJson(new JsonObject()).getBytes(StandardCharsets.UTF_8);
byte[] archiveBytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
TarArchiveEntry tarEntry;
tarEntry = new TarArchiveEntry("image-id-sha256.json");
tarEntry.setSize(relatedData.length);
tarOutput.putArchiveEntry(tarEntry);
tarOutput.write(relatedData);
tarOutput.closeArchiveEntry();
tarEntry = new TarArchiveEntry(ImageArchiveUtil.MANIFEST_JSON);
tarEntry.setSize(entryData.length);
tarOutput.putArchiveEntry(tarEntry);
tarOutput.write(entryData);
tarOutput.closeArchiveEntry();
tarOutput.finish();
archiveBytes = baos.toByteArray();
}
ImageArchiveManifest manifest = ImageArchiveUtil.readManifest(new ByteArrayInputStream(archiveBytes));
Assert.assertNotNull(manifest);
Assert.assertNotNull(manifest.getEntries());
Assert.assertFalse(manifest.getEntries().isEmpty());
ImageArchiveManifestEntry entry = manifest.getEntries().get(0);
Assert.assertNotNull(entry);
Assert.assertEquals("image-id-sha256.json", entry.getConfig());
Assert.assertEquals("image-id-sha256", entry.getId());
Assert.assertNotNull(entry.getRepoTags());
Assert.assertEquals(Collections.singletonList("test/image:latest"), entry.getRepoTags());
Assert.assertNotNull(entry.getLayers());
Assert.assertEquals(Collections.singletonList("layer-id-sha256/layer.tar"), entry.getLayers());
}
Aggregations