@Test public void checkImagesAreFoundCorrectly() { Assert.assertNull(DockerUtils.findImageByIdOrByTag("oops81:unknown", this.docker)); Assert.assertNotNull(DockerUtils.findImageByIdOrByTag("ubuntu", this.docker)); Assert.assertNotNull(DockerUtils.findImageByIdOrByTag("ubuntu:latest", this.docker)); }
/** * Prepares the docker environment (image, etc...) for testing. * * @throws IOException */ private void prepareDockerTest() throws Exception { final String tag = "roboconf-test"; Builder config = DefaultDockerClientConfig.createDefaultConfigBuilder(); config.withDockerHost("tcp://localhost:" + DockerTestUtils.DOCKER_TCP_PORT); this.docker = DockerClientBuilder.getInstance(config.build()).build(); File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("./image").getFile()); String builtImageId = this.docker .buildImageCmd(baseDir) .withNoCache(true) .withTag(tag) .exec(new RoboconfBuildImageResultCallback()) .awaitImageId(); this.logger.finest("Built image ID: " + builtImageId); List<Image> images = this.docker.listImagesCmd().exec(); images = images == null ? new ArrayList<Image>(0) : images; Image img = DockerUtils.findImageByTag(tag, images); this.dockerImageId = img.getId(); }
@Test public void testValidConfiguration() throws Exception { Assume.assumeTrue(this.dockerIsInstalled); Map<String, String> targetProperties = loadTargetProperties(); DockerClient client = DockerUtils.createDockerClient(targetProperties); Assert.assertNotNull(client); }
@Test public void testDockerUtils_onLimits() { DockerUtils.deleteImageIfItExists(null, this.docker); Assert.assertTrue("No exception is thrown trying to delete a null image ID.", true); DockerUtils.deleteImageIfItExists("bla 11 4 2 bla", this.docker); Assert.assertTrue( "No exception is thrown trying to delete something that does not exist.", true); Container container = DockerUtils.findContainerByIdOrByName("bla 11 4 2 bla", this.docker); Assert.assertNull(container); Image image = DockerUtils.findImageByIdOrByTag(null, this.docker); Assert.assertNull(image); image = DockerUtils.findImageByIdOrByTag("invalid", this.docker); Assert.assertNull(image); }
@After public void dockerCleanup() { if (this.docker != null) { DockerUtils.deleteImageIfItExists(this.dockerImageId, this.docker); try { this.docker.close(); } catch (IOException e) { // nothing } } }
@Test(expected = TargetException.class) public void testConfigureVM_invalidBaseImage() throws Exception { Assume.assumeTrue(this.dockerIsInstalled); Map<String, String> targetProperties = loadTargetProperties(); targetProperties.put(DockerHandler.IMAGE_ID, "will-not-be-generated"); targetProperties.put(DockerHandler.BASE_IMAGE, "oops81:unknown"); DockerMachineConfigurator configurator = new DockerMachineConfigurator( targetProperties, this.msgCfg, "656sdf6sd", "/test", "app", new Instance()); try { configurator.dockerClient = this.docker; configurator.createImage("will-not-be-generated"); } finally { configurator.dockerClient = null; configurator.close(); Assert.assertNull(DockerUtils.findImageByIdOrByTag("will-not-be-generated", this.docker)); } }