Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed May 20, 2023
1 parent 1a96e98 commit 040c935
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ public void beforeContainerCreated(DockerAPI api, String workdir, CreateContaine
final String[] resolvedArgs = splitAndFilterEmpty(resolvedArgString, "\n");

cmd.withCmd(resolvedArgs);
String vmargs = jnlpLauncher.vmargs;
if (StringUtils.isNotBlank(vmargs)) {
DockerEnvUtils.addEnvToCmd("JAVA_OPT", vmargs.trim(), cmd);
}
if (StringUtils.isNotBlank(user)) {
cmd.withUser(user);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package io.jenkins.docker.connector;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.github.dockerjava.api.command.CreateContainerCmd;
import com.nirima.jenkins.plugins.docker.DockerTemplate;
import com.nirima.jenkins.plugins.docker.DockerTemplateBase;

Expand All @@ -14,10 +8,7 @@
import org.apache.commons.lang3.SystemUtils;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.TreeMap;

public class DockerComputerJNLPConnectorTest extends DockerComputerConnectorTest {
private static final String JNLP_AGENT_IMAGE_IMAGENAME = "jenkins/inbound-agent";
Expand Down Expand Up @@ -50,48 +41,4 @@ public void connectAgentViaJNLP() throws Exception {
template.setName("connectAgentViaJNLP");
should_connect_agent(template);
}

@Test
public void testKeepingEvnInBeforeContainerCreated() throws IOException, InterruptedException {
// Given
final String env1 = "ENV1=val1";
final String vmargs = "-Dhttp.proxyPort=8080";
final DockerComputerJNLPConnector connector = new DockerComputerJNLPConnector(new JNLPLauncher(null, vmargs));

final CreateContainerCmd createCmd = mock(CreateContainerCmd.class);
final Map<String, String> containerLabels = new TreeMap<>();
when(createCmd.getLabels()).thenReturn(containerLabels);
DockerTemplate.setNodeNameInContainerConfig(createCmd, "nodeName");
when(createCmd.getEnv()).thenReturn(new String[]{ env1 });

// When
connector.beforeContainerCreated(null, null, createCmd);

// Then
verify(createCmd, times(1)).withEnv(new String[]{
env1,
"JAVA_OPT=" + vmargs
});
}

@Test
public void testAddingVmargsInBeforeContainerCreated() throws IOException, InterruptedException {
// Given
final String vmargs = "-Dhttp.proxyPort=8080";
final DockerComputerJNLPConnector connector = new DockerComputerJNLPConnector(new JNLPLauncher(null, vmargs));

final CreateContainerCmd createCmd = mock(CreateContainerCmd.class);
final Map<String, String> containerLabels = new TreeMap<>();
when(createCmd.getLabels()).thenReturn(containerLabels);
DockerTemplate.setNodeNameInContainerConfig(createCmd, "nodeName");

// When
connector.beforeContainerCreated(null, null, createCmd);

// Then
verify(createCmd, times(1)).withEnv(new String[]{
"JAVA_OPT=" + vmargs
});
}

}

0 comments on commit 040c935

Please sign in to comment.