Search in sources :

Example 1 with UnixSocketConnectionSettings

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

the class EditDockerConnectionSWTBotTest method shouldUpdateTCPConnectionSettingsWithValidConnectionAvailable.

@Test
public void shouldUpdateTCPConnectionSettingsWithValidConnectionAvailable() {
    // given
    configureTCPConnection();
    openConnectionEditionWizard("Test");
    // when: switch to TCP connection settings and save
    bot.text(0).setText("foo");
    bot.radio(0).click();
    bot.text(1).setText("/var/run/docker.sock");
    getFinishButton().click();
    // then
    final IDockerConnection fooConnection = DockerConnectionManager.getInstance().findConnection("foo");
    assertThat(fooConnection).isNotNull();
    assertThat(fooConnection.getName()).isEqualTo("foo");
    assertThat(fooConnection.getSettings()).isInstanceOf(UnixSocketConnectionSettings.class);
    final UnixSocketConnectionSettings connectionSettings = (UnixSocketConnectionSettings) fooConnection.getSettings();
    assertThat(connectionSettings.getPath()).isEqualTo("unix:///var/run/docker.sock");
}
Also used : UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Test(org.junit.Test)

Example 2 with UnixSocketConnectionSettings

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

the class EditDockerConnectionSWTBotTest method shouldResetConnectionStateWhenUnixConnectionSettingsChanged.

@Test
public void shouldResetConnectionStateWhenUnixConnectionSettingsChanged() throws IOException {
    // given
    dockerContainers.close();
    dockerImages.close();
    final IDockerConnection connection = configureUnixSocketConnection("Test");
    final IDockerConnectionStorageManager connectionStorageManager = MockDockerConnectionStorageManagerFactory.providing(connection);
    DockerConnectionManagerUtils.configureConnectionManager(connectionStorageManager);
    final SWTBotTreeItem connectionTreeItem = SWTUtils.getTreeItem(dockerExplorer.bot(), "Test");
    assertThat(connectionTreeItem).isNotNull();
    final File tmpDockerSocketFile = folder.newFile("docker.sock");
    assertThat(connection.getState()).isEqualTo(EnumDockerConnectionState.UNKNOWN);
    // when
    openConnectionEditionWizard("Test");
    bot.text(1).setText(tmpDockerSocketFile.getAbsolutePath());
    getFinishButton().click();
    // then
    final IDockerConnection foundConnection = DockerConnectionManager.getInstance().findConnection("Test");
    assertThat(foundConnection).isNotNull();
    assertThat(foundConnection.getSettings()).isNotNull().isEqualTo(new UnixSocketConnectionSettings(tmpDockerSocketFile.getAbsolutePath()));
    assertThat(foundConnection.getState()).isEqualTo(EnumDockerConnectionState.UNKNOWN);
}
Also used : IDockerConnectionStorageManager(org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) File(java.io.File) Test(org.junit.Test)

Example 3 with UnixSocketConnectionSettings

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

the class EditDockerConnectionSWTBotTest method shouldSaveConnectionWhenUnixSocketConnectionSettingsChanged.

@SuppressWarnings("unchecked")
@Test
public void shouldSaveConnectionWhenUnixSocketConnectionSettingsChanged() throws IOException {
    // given
    final IDockerConnection connection = configureUnixSocketConnection("Test");
    final IDockerConnectionStorageManager connectionStorageManager = MockDockerConnectionStorageManagerFactory.providing(connection);
    DockerConnectionManagerUtils.configureConnectionManager(connectionStorageManager);
    final SWTBotTreeItem connectionTreeItem = SWTUtils.getTreeItem(dockerExplorer.bot(), "Test");
    assertThat(connectionTreeItem).isNotNull();
    final File tmpDockerSocketFile = folder.newFile("docker.sock");
    // let's ignore the connection savings that may have occurred when
    // adding elements from the extension points
    Mockito.reset(connectionStorageManager);
    // when
    openConnectionEditionWizard("Test");
    bot.text(1).setText(tmpDockerSocketFile.getAbsolutePath());
    getFinishButton().click();
    // then
    final IDockerConnection foundConnection = DockerConnectionManager.getInstance().findConnection("Test");
    assertThat(foundConnection).isNotNull();
    assertThat(foundConnection.getSettings()).isNotNull().isEqualTo(new UnixSocketConnectionSettings(tmpDockerSocketFile.getAbsolutePath()));
    Mockito.verify(connectionStorageManager).saveConnections(Matchers.anyList());
}
Also used : IDockerConnectionStorageManager(org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) File(java.io.File) Test(org.junit.Test)

Example 4 with UnixSocketConnectionSettings

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

the class DockerConnectionManagerTest method testExtensionPointProvidedConnections.

@Test
public void testExtensionPointProvidedConnections() {
    DefaultDockerConnectionSettingsFinder finder = new DefaultDockerConnectionSettingsFinder();
    List<IDockerConnectionSettings> settings = finder.getKnownConnectionSettings();
    assertTrue(settings.size() > 0);
    for (IDockerConnectionSettings s : settings) {
        if (s instanceof TCPConnectionSettings) {
            TCPConnectionSettings t = (TCPConnectionSettings) s;
            assertThat(t.getType()).isEqualTo(BindingType.TCP_CONNECTION);
            assertThat(t.getHost()).isEqualTo("https://1.2.3.4:5678");
            assertThat(t.getPathToCertificates()).isEqualTo("/foo/bar/baz/certs");
            assertThat(t.getName()).isEqualTo("https://1.2.3.4:5678");
        } else if (s instanceof UnixSocketConnectionSettings) {
            UnixSocketConnectionSettings t = (UnixSocketConnectionSettings) s;
            // skip if this is the Linux native or Docker for Mac daemon
            if (t.getPath().equals("unix:///var/run/docker.sock")) {
                continue;
            }
            assertThat(t.getType()).isEqualTo(BindingType.UNIX_SOCKET_CONNECTION);
            assertThat(t.getPath()).isEqualTo("unix:///foo/bar/baz/docker.sock");
            assertThat(t.getName()).isEqualTo("unix:///foo/bar/baz/docker.sock");
        } else {
            fail("Docker Connection Settings does not match a known type");
        }
    }
}
Also used : DefaultDockerConnectionSettingsFinder(org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) Test(org.junit.Test)

Example 5 with UnixSocketConnectionSettings

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

the class MockDockerConnectionSettingsFinder method validUnixSocketConnectionAvailable.

/**
 * Configures the {@link DockerConnectionManager} singleton to being able to
 * detect a <strong>valid Unix Socket</strong> to a Docker daemon.
 */
public static void validUnixSocketConnectionAvailable(final String connectionName, final String unixSocketPath) {
    final IDockerConnectionSettingsFinder validUnixSocketConnectionAvailable = Mockito.mock(IDockerConnectionSettingsFinder.class);
    final UnixSocketConnectionSettings unixSocketConnectionSettings = new UnixSocketConnectionSettings(unixSocketPath);
    // unixSocketConnectionSettings.setName("mock");
    unixSocketConnectionSettings.setSettingsResolved(true);
    Mockito.when(validUnixSocketConnectionAvailable.findDefaultConnectionSettings()).thenReturn(unixSocketConnectionSettings);
    Mockito.when(validUnixSocketConnectionAvailable.resolveConnectionName(Matchers.any(IDockerConnectionSettings.class))).thenReturn(connectionName);
    DockerConnectionManager.getInstance().setConnectionSettingsFinder(validUnixSocketConnectionAvailable);
}
Also used : IDockerConnectionSettingsFinder(org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsFinder) UnixSocketConnectionSettings(org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings) IDockerConnectionSettings(org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)

Aggregations

UnixSocketConnectionSettings (org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings)7 Test (org.junit.Test)4 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)3 TCPConnectionSettings (org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)3 File (java.io.File)2 IDockerConnectionSettings (org.eclipse.linuxtools.docker.core.IDockerConnectionSettings)2 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DockerConnectionManager (org.eclipse.linuxtools.docker.core.DockerConnectionManager)1 IDockerConnectionSettingsFinder (org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsFinder)1 DefaultDockerConnectionSettingsFinder (org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder)1 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)1