Search in sources :

Example 6 with ImageArchiveManifest

use of io.fabric8.maven.docker.model.ImageArchiveManifest in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findByRepoTagPatternInvalidPattern.

@Test(expected = PatternSyntaxException.class)
public void findByRepoTagPatternInvalidPattern() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern("*(?", nonEmpty));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 7 with ImageArchiveManifest

use of io.fabric8.maven.docker.model.ImageArchiveManifest in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findByRepoTagEmptyManifest.

@Test
public void findByRepoTagEmptyManifest() {
    ImageArchiveManifest empty = new ImageArchiveManifestAdapter(new JsonArray());
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTag("anything", empty));
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTag("anything", null));
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTag(null, null));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) JsonArray(com.google.gson.JsonArray) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 8 with ImageArchiveManifest

use of io.fabric8.maven.docker.model.ImageArchiveManifest in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findEntriesByRepoTagPatternInvalidPattern.

@Test(expected = PatternSyntaxException.class)
public void findEntriesByRepoTagPatternInvalidPattern() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    Assert.assertNull(ImageArchiveUtil.findEntryByRepoTagPattern("*(?", nonEmpty));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 9 with ImageArchiveManifest

use of io.fabric8.maven.docker.model.ImageArchiveManifest in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method readInvalidJsonInArchive.

@Test
public void readInvalidJsonInArchive() throws IOException {
    byte[] archiveBytes;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
        TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(baos)) {
        final byte[] entryData = ("}" + UUID.randomUUID().toString() + "{").getBytes();
        TarArchiveEntry tarEntry = new TarArchiveEntry("not-the-" + 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.assertNull(manifest);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) Test(org.junit.Test)

Example 10 with ImageArchiveManifest

use of io.fabric8.maven.docker.model.ImageArchiveManifest in project docker-maven-plugin by fabric8io.

the class ImageArchiveUtilTest method findEntriesByRepoTagPatternSuccessfully.

@Test
public void findEntriesByRepoTagPatternSuccessfully() {
    ImageArchiveManifest nonEmpty = new ImageArchiveManifestAdapter(createBasicManifestJson());
    Map<String, ImageArchiveManifestEntry> entries;
    // Complete match
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("test/image:latest", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
    // Unanchored match
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("test/image", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
    // Initial anchor
    entries = ImageArchiveUtil.findEntriesByRepoTagPattern("^test/image", nonEmpty);
    Assert.assertNotNull(entries);
    Assert.assertNotNull(entries.get("test/image:latest"));
    Assert.assertTrue(entries.get("test/image:latest").getRepoTags().contains("test/image:latest"));
}
Also used : ImageArchiveManifestAdapter(io.fabric8.maven.docker.model.ImageArchiveManifestAdapter) ImageArchiveManifest(io.fabric8.maven.docker.model.ImageArchiveManifest) ImageArchiveManifestEntry(io.fabric8.maven.docker.model.ImageArchiveManifestEntry) Test(org.junit.Test)

Aggregations

ImageArchiveManifest (io.fabric8.maven.docker.model.ImageArchiveManifest)22 Test (org.junit.Test)20 ImageArchiveManifestAdapter (io.fabric8.maven.docker.model.ImageArchiveManifestAdapter)13 ImageArchiveManifestEntry (io.fabric8.maven.docker.model.ImageArchiveManifestEntry)10 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)5 JsonArray (com.google.gson.JsonArray)3 Gson (com.google.gson.Gson)2 JsonParseException (com.google.gson.JsonParseException)2 LinkedHashMap (java.util.LinkedHashMap)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Matcher (java.util.regex.Matcher)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1