-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper parsing of empty dnsHosts string
When DNS hosts are empty, plugin sends DNS override to docker container ("Dns":[""]). With this patch, correctly declines to override dns when the cloud configuration does not ask for it.
- Loading branch information
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/com/nirima/jenkins/plugins/docker/DockerTemplateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.nirima.jenkins.plugins.docker; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class DockerTemplateTest { | ||
|
||
private DockerTemplate getDockerTemplateInstanceWithDNSHost(String dnsString) { | ||
DockerTemplate instance = new DockerTemplate("image", null, "remoteFs", "credentialsId", " jvmOptions", " javaPath", "prefixStartSlaveCmd", " suffixStartSlaveCmd", "", dnsString, "dockerCommand", "volumes", "hostname", false); | ||
return instance; | ||
} | ||
|
||
@Test | ||
public void testDnsHosts() { | ||
DockerTemplate instance; | ||
String[] expected; | ||
|
||
instance = getDockerTemplateInstanceWithDNSHost(""); | ||
assertEquals(0, instance.dnsHosts.length); | ||
|
||
instance = getDockerTemplateInstanceWithDNSHost("8.8.8.8"); | ||
expected = new String[]{"8.8.8.8"}; | ||
|
||
assertEquals(1, instance.dnsHosts.length); | ||
assertArrayEquals(expected, instance.dnsHosts); | ||
|
||
instance = getDockerTemplateInstanceWithDNSHost("8.8.8.8 8.8.4.4"); | ||
expected = new String[]{"8.8.8.8", "8.8.4.4"}; | ||
|
||
assertEquals(2, instance.dnsHosts.length); | ||
assertArrayEquals(expected, instance.dnsHosts); | ||
|
||
} | ||
|
||
} |