Search in sources :

Example 36 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ImageRunSWTBotTest method shouldNotReportErrorIfNoContainerWithSameNameExists.

@Test
public void shouldNotReportErrorIfNoContainerWithSameNameExists() {
    // given
    final DockerClient client = MockDockerClientFactory.image(MockImageFactory.name("foo:latest").build()).container(MockContainerFactory.name("foo_bar").build()).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    // expand the 'Images' node and select the 'foo' images
    SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo").select();
    // when opening the "Run Image..." wizard
    final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
    dockerExplorerViewTreeBot.contextMenu("Run...").click();
    // when use an existing container name
    bot.textWithLabel(WizardMessages.getString("ImageRunSelectionPage.containerName")).setText("foo_bar_baz");
    // then
    assertThat(bot.button("Finish").isEnabled()).isEqualTo(true);
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) Test(org.junit.Test)

Example 37 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ImageRunSWTBotTest method shouldCreateLaunchConfigurationWhenRunningNamedContainer.

@Test
public void shouldCreateLaunchConfigurationWhenRunningNamedContainer() throws InterruptedException, DockerException, CoreException {
    // images to use
    final String imageName = "foo/bar:latest";
    final Image image = MockImageFactory.id("1a2b3c4d5e6f7g").name(imageName).build();
    final ImageInfo imageInfo = MockImageInfoFactory.volume("/foo/bar").command(Arrays.asList("the", "command")).entrypoint(Arrays.asList("the", "entrypoint")).build();
    // container to be created
    final String containerName = "foo_bar";
    final Container createdContainer = MockContainerFactory.id("MockContainer").name(containerName).imageName("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
    final ContainerInfo containerInfo = MockContainerInfoFactory.build();
    final DockerClient client = MockDockerClientFactory.image(image, imageInfo).build();
    // expected response when creating the container
    final ContainerCreation containerCreation = Mockito.mock(ContainerCreation.class);
    Mockito.when(containerCreation.id()).thenReturn("MockContainer");
    Mockito.when(client.createContainer(Matchers.any(), Matchers.any())).thenReturn(containerCreation);
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    // configure the Connection Manager
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    // when select images and click on run to open the wizard
    SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo/bar").select();
    dockerExplorerViewBot.bot().tree().contextMenu("Run...").click();
    // $NON-NLS-1$
    bot.waitUntil(Conditions.shellIsActive("Run a Docker Image"), TimeUnit.SECONDS.toMillis(1));
    // configure container
    bot.text(0).setText(containerName);
    // bot.button("Next >").click();
    // update the client to make sure the container exists once the call to "Finish" is done
    MockDockerClientFactory.addContainer(client, createdContainer, containerInfo);
    bot.button("Finish").click();
    // wait for background job to complete
    SWTUtils.waitForJobsToComplete();
    // then
    // check that the client was called
    Mockito.verify(client).createContainer(Matchers.any(), Matchers.eq(containerName));
    // check that a launch configuration was created
    final ILaunchConfiguration launchConfiguration = LaunchConfigurationUtils.getLaunchConfigurationByName(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID, "foo_bar_latest");
    assertThat(launchConfiguration).isNotNull();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) Container(com.spotify.docker.client.messages.Container) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerClient(com.spotify.docker.client.DockerClient) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) ImageInfo(com.spotify.docker.client.messages.ImageInfo) Test(org.junit.Test)

Example 38 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ImageRunSWTBotTest method testNetworkModeOther.

@Test
public void testNetworkModeOther() throws CoreException {
    final DockerClient client = MockDockerClientFactory.image(MockImageFactory.name("foo:latest").build()).container(MockContainerFactory.name("foo_bar").build()).build();
    final DockerConnection connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    final String runImageLaunchConfigurationName = configureRunImageLaunchConfiguration(connection, "jeffnet");
    final ILaunchConfiguration runDockerImageLaunchConfig = LaunchConfigurationUtils.getLaunchConfigurationByName(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID, runImageLaunchConfigurationName);
    assertThat(runDockerImageLaunchConfig).isNotNull();
    assertThat(runDockerImageLaunchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, "")).isEqualTo("Test");
    assertThat(runDockerImageLaunchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.NETWORK_MODE, "")).isEqualTo("jeffnet");
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerClient(com.spotify.docker.client.DockerClient) Test(org.junit.Test)

Example 39 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ImageRunSWTBotTest method testNetworkModeBridge.

@Test
public void testNetworkModeBridge() throws CoreException {
    final DockerClient client = MockDockerClientFactory.image(MockImageFactory.name("foo:latest").build()).container(MockContainerFactory.name("foo_bar").build()).build();
    final DockerConnection connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    final String runImageLaunchConfigurationName = configureRunImageLaunchConfiguration(connection, "bridge");
    final ILaunchConfiguration runDockerImageLaunchConfig = LaunchConfigurationUtils.getLaunchConfigurationByName(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID, runImageLaunchConfigurationName);
    assertThat(runDockerImageLaunchConfig).isNotNull();
    assertThat(runDockerImageLaunchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, "")).isEqualTo("Test");
    assertThat(runDockerImageLaunchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.NETWORK_MODE, "")).isEqualTo("bridge");
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerClient(com.spotify.docker.client.DockerClient) Test(org.junit.Test)

Example 40 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ImageSearchSWTBotTest method openPullWizard.

private void openPullWizard(final DockerClient client) {
    // given
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    // expand the 'Images' node
    final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
    // when opening the "Pull..." wizard
    final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
    imagesTreeItem.select();
    dockerExplorerViewTreeBot.contextMenu("Pull...").click();
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)

Aggregations

DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)108 DockerClient (com.spotify.docker.client.DockerClient)75 Test (org.junit.Test)71 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)31 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)21 DockerException (org.eclipse.linuxtools.docker.core.DockerException)18 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)15 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)9 RunWithProject (org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Job (org.eclipse.core.runtime.jobs.Job)8 Path (java.nio.file.Path)6 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)6 ProgressHandler (com.spotify.docker.client.ProgressHandler)5 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)5 PropertySheet (org.eclipse.ui.views.properties.PropertySheet)5 TabbedPropertySheetPage (org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)5 Before (org.junit.Before)5 File (java.io.File)4 IOException (java.io.IOException)4