@@ -17,6 +17,8 @@ $global:WINDOWSVERSIONTAG = $items[2]
1717
1818$random = Get-Random
1919$global :CONTAINERNAME = ' pester-jenkins-inbound-agent_{0}_{1}' -f $global :IMAGE_TAG , $random
20+ $global :JNLPNETWORKNAME = ' jnlp-{0}' -f $random
21+ $global :NMAPCONTAINERNAME = ' nmap-{0}' -f $random
2022Write-Host " = TESTS: container name $global :CONTAINERNAME "
2123
2224$global :CONTAINERSHELL = ' powershell.exe'
@@ -31,8 +33,8 @@ if ($global:WINDOWSFLAVOR -eq 'nanoserver') {
3133# Get-ChildItem Env: | ForEach-Object { Write-Host "$($_.Name) = $($_.Value)" }
3234
3335Cleanup($global :CONTAINERNAME )
34- Cleanup(' nmap ' )
35- CleanupNetwork(' jnlp-network ' )
36+ Cleanup($ global :NMAPCONTAINERNAME )
37+ CleanupNetwork($ global :JNLPNETWORKNAME )
3638
3739BuildNcatImage($global :WINDOWSVERSIONTAG )
3840
@@ -84,36 +86,36 @@ Describe "[$global:IMAGE_NAME] image has jenkins-agent.ps1 in the correct locati
8486
8587Describe " [$global :IMAGE_NAME ] image starts jenkins-agent.ps1 correctly (slow test)" {
8688 It ' connects to the nmap container' {
87- $exitCode , $stdout , $stderr = Run- Program ' docker' ' network create --driver nat jnlp-network '
89+ $exitCode , $stdout , $stderr = Run- Program ' docker' " network create --driver nat $ global :JNLPNETWORKNAME "
8890 # Launch the netcat utility, listening at port 5000 for 30 sec
8991 # bats will capture the output from netcat and compare the first line
9092 # of the header of the first HTTP request with the expected one
91- $exitCode , $stdout , $stderr = Run- Program ' docker' ' run --detach --tty --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000'
93+ $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --name $ global :NMAPCONTAINERNAME --network=$ global :JNLPNETWORKNAME nmap:latest ncat.exe -w 30 -l 5000"
9294 $exitCode | Should - Be 0
93- Is- ContainerRunning " nmap " | Should - BeTrue
95+ Is- ContainerRunning $ global :NMAPCONTAINERNAME | Should - BeTrue
9496
9597 # get the ip address of the nmap container
96- $exitCode , $stdout , $stderr = Run- Program ' docker' " inspect --format `" {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap "
98+ $exitCode , $stdout , $stderr = Run- Program ' docker' " inspect --format `" {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" $ global :NMAPCONTAINERNAME "
9799 $exitCode | Should - Be 0
98100 $nmap_ip = $stdout.Trim ()
99101
100102 # run Jenkins agent which tries to connect to the nmap container at port 5000
101103 $secret = " aaa"
102104 $name = " bbb"
103- $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --network=jnlp-network --name $global :CONTAINERNAME $global :IMAGE_NAME -Url http://${nmap_ip} :5000 $secret $name "
105+ $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --network=$ global :JNLPNETWORKNAME --name $global :CONTAINERNAME $global :IMAGE_NAME -Url http://${nmap_ip} :5000 $secret $name "
104106 $exitCode | Should - Be 0
105107 Is- ContainerRunning $global :CONTAINERNAME | Should - BeTrue
106108
107- $exitCode , $stdout , $stderr = Run- Program ' docker' ' wait nmap '
108- $exitCode , $stdout , $stderr = Run- Program ' docker' ' logs nmap '
109+ $exitCode , $stdout , $stderr = Run- Program ' docker' " wait $ global :NMAPCONTAINERNAME "
110+ $exitCode , $stdout , $stderr = Run- Program ' docker' " logs $ global :NMAPCONTAINERNAME "
109111 $exitCode | Should - Be 0
110112 $stdout | Should -Match " GET /tcpSlaveAgentListener/ HTTP/1.1`r "
111113 }
112114
113115 AfterAll {
114116 Cleanup($global :CONTAINERNAME )
115- Cleanup(' nmap ' )
116- CleanupNetwork(' jnlp-network ' )
117+ Cleanup($ global :NMAPCONTAINERNAME )
118+ CleanupNetwork($ global :JNLPNETWORKNAME )
117119 }
118120}
119121
@@ -148,24 +150,24 @@ Describe "[$global:IMAGE_NAME] custom build args" {
148150}
149151
150152Describe " [$global :IMAGE_NAME ] passing JVM options (slow test)" {
151- It " shows the java version ${ global:JAVAMAJORVERSION } with --show-version" {
152- $exitCode , $stdout , $stderr = Run- Program ' docker' ' network create --driver nat jnlp-network '
153+ It " connects to the nmap container and shows the java version ${ global:JAVAMAJORVERSION } with --show-version" {
154+ $exitCode , $stdout , $stderr = Run- Program ' docker' " network create --driver nat $ global :JNLPNETWORKNAME "
153155 # Launch the netcat utility, listening at port 5000 for 30 sec
154156 # bats will capture the output from netcat and compare the first line
155157 # of the header of the first HTTP request with the expected one
156- $exitCode , $stdout , $stderr = Run- Program ' docker' ' run --detach --tty --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000'
158+ $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --name $ global :NMAPCONTAINERNAME --network=$ global :JNLPNETWORKNAME nmap:latest ncat.exe -w 30 -l 5000"
157159 $exitCode | Should - Be 0
158- Is- ContainerRunning ' nmap ' | Should - BeTrue
160+ Is- ContainerRunning $ global :NMAPCONTAINERNAME | Should - BeTrue
159161
160162 # get the ip address of the nmap container
161- $exitCode , $stdout , $stderr = Run- Program ' docker' " inspect --format `" {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap "
163+ $exitCode , $stdout , $stderr = Run- Program ' docker' " inspect --format `" {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" $ global :NMAPCONTAINERNAME "
162164 $exitCode | Should - Be 0
163165 $nmap_ip = $stdout.Trim ()
164166
165167 # run Jenkins agent which tries to connect to the nmap container at port 5000
166168 $secret = ' aaa'
167169 $name = ' bbb'
168- $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --network=jnlp-network --name $global :CONTAINERNAME $global :IMAGE_NAME -Url http://${nmap_ip} :5000 -JenkinsJavaOpts `" --show-version`" $secret $name "
170+ $exitCode , $stdout , $stderr = Run- Program ' docker' " run --detach --tty --network=$ global :JNLPNETWORKNAME --name $global :CONTAINERNAME $global :IMAGE_NAME -Url http://${nmap_ip} :5000 -JenkinsJavaOpts `" --show-version`" $secret $name "
169171 $exitCode | Should - Be 0
170172 Is- ContainerRunning $global :CONTAINERNAME | Should - BeTrue
171173 Start-Sleep - Seconds 20
@@ -176,7 +178,7 @@ Describe "[$global:IMAGE_NAME] passing JVM options (slow test)" {
176178
177179 AfterAll {
178180 Cleanup($global :CONTAINERNAME )
179- Cleanup(' nmap ' )
180- CleanupNetwork(' jnlp-network ' )
181+ Cleanup($ global :NMAPCONTAINERNAME )
182+ CleanupNetwork($ global :JNLPNETWORKNAME )
181183 }
182184}
0 commit comments