From 25c16d0c4bbac28eb4d51691d21f5e721bedce7f Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Sun, 30 Apr 2023 10:55:16 +0200 Subject: [PATCH] chore(windows tests) fix harness to use long flags, no more interactive flag and same build command make.ps1 Signed-off-by: Damien Duportal --- tests/inboundAgent.Tests.ps1 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/inboundAgent.Tests.ps1 b/tests/inboundAgent.Tests.ps1 index 01af53dee..d4277fa6c 100644 --- a/tests/inboundAgent.Tests.ps1 +++ b/tests/inboundAgent.Tests.ps1 @@ -5,7 +5,6 @@ $global:AGENT_CONTAINER='pester-jenkins-inbound-agent' $global:SHELL="powershell.exe" $global:FOLDER = Get-EnvOrDefault 'FOLDER' '' -$global:VERSION = Get-EnvOrDefault 'VERSION' '4.9-1' $REAL_FOLDER=Resolve-Path -Path "$PSScriptRoot/../${global:FOLDER}" @@ -38,22 +37,22 @@ BuildNcatImage Describe "[$global:JDK $global:FLAVOR] build image" { BeforeAll { - Push-Location -StackName 'agent' -Path "$PSScriptRoot/.." + Push-Location -StackName 'agent' -Path "$PSScriptRoot/.." } It 'builds image' { - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg VERSION=$global:VERSION -t $global:AGENT_IMAGE $global:FOLDER" - $exitCode | Should -Be 0 + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --tag $global:AGENT_IMAGE --file $global:FOLDER/Dockerfile ./" + $exitCode | Should -Be 0 } AfterAll { - Pop-Location -StackName 'agent' + Pop-Location -StackName 'agent' } } Describe "[$global:JDK $global:FLAVOR] check default user account" { BeforeAll { - docker run -d -it --name "$global:AGENT_CONTAINER" -P "$global:AGENT_IMAGE" -Cmd "$global:SHELL" + docker run --detach --tty --name "$global:AGENT_CONTAINER" "$global:AGENT_IMAGE" -Cmd "$global:SHELL" $LASTEXITCODE | Should -Be 0 Is-ContainerRunning $global:AGENT_CONTAINER | Should -BeTrue } @@ -75,7 +74,8 @@ Describe "[$global:JDK $global:FLAVOR] check default user account" { Describe "[$global:JDK $global:FLAVOR] image has jenkins-agent.ps1 in the correct location" { BeforeAll { - & docker run -dit --name "$global:AGENT_CONTAINER" -P "$global:AGENT_IMAGE" -Cmd $global:SHELL + docker run --detach --tty --name "$global:AGENT_CONTAINER" "$global:AGENT_IMAGE" -Cmd "$global:SHELL" + $LASTEXITCODE | Should -Be 0 Is-ContainerRunning $global:AGENT_CONTAINER | Should -BeTrue } @@ -95,19 +95,19 @@ Describe "[$global:JDK $global:FLAVOR] image starts jenkins-agent.ps1 correctly # Launch the netcat utility, listening at port 5000 for 30 sec # bats will capture the output from netcat and compare the first line # of the header of the first HTTP request with the expected one - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run --detach --tty --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000" $exitCode | Should -Be 0 Is-ContainerRunning "nmap" | Should -BeTrue # get the ip address of the nmap container - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect -f `"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect --format `"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap" $exitCode | Should -Be 0 $nmap_ip = $stdout.Trim() # run Jenkins agent which tries to connect to the nmap container at port 5000 $secret = "aaa" $name = "bbb" - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --network=jnlp-network --name $global:AGENT_CONTAINER $global:AGENT_IMAGE -Url http://${nmap_ip}:5000 $secret $name" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run --detach --tty --network=jnlp-network --name $global:AGENT_CONTAINER $global:AGENT_IMAGE -Url http://${nmap_ip}:5000 $secret $name" $exitCode | Should -Be 0 Is-ContainerRunning $global:AGENT_CONTAINER | Should -BeTrue @@ -139,7 +139,7 @@ Describe "[$global:JDK $global:FLAVOR] build args" { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg version=${ARG_TEST_VERSION} --build-arg user=$TEST_USER -t $global:AGENT_IMAGE $global:FOLDER" $exitCode | Should -Be 0 - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --name $global:AGENT_CONTAINER -P $global:AGENT_IMAGE -Cmd $global:SHELL" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run --detach --tty --name $global:AGENT_CONTAINER $global:AGENT_IMAGE -Cmd $global:SHELL" $exitCode | Should -Be 0 Is-ContainerRunning "$global:AGENT_CONTAINER" | Should -BeTrue } @@ -172,26 +172,25 @@ Describe "[$global:JDK $global:FLAVOR] build args" { } } - Describe "[$global:JDK $global:FLAVOR] passing JVM options (slow test)" { It "shows the java version with --show-version" { $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "network create --driver nat jnlp-network" # Launch the netcat utility, listening at port 5000 for 30 sec # bats will capture the output from netcat and compare the first line # of the header of the first HTTP request with the expected one - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run --detach --tty --name nmap --network=jnlp-network nmap:latest ncat.exe -w 30 -l 5000" $exitCode | Should -Be 0 Is-ContainerRunning "nmap" | Should -BeTrue # get the ip address of the nmap container - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect -f `"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "inspect --format `"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}`" nmap" $exitCode | Should -Be 0 $nmap_ip = $stdout.Trim() # run Jenkins agent which tries to connect to the nmap container at port 5000 $secret = "aaa" $name = "bbb" - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --network=jnlp-network --name $global:AGENT_CONTAINER $global:AGENT_IMAGE -Url http://${nmap_ip}:5000 -JenkinsJavaOpts `"--show-version`" $secret $name" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run --detach --tty --network=jnlp-network --name $global:AGENT_CONTAINER $global:AGENT_IMAGE -Url http://${nmap_ip}:5000 -JenkinsJavaOpts `"--show-version`" $secret $name" $exitCode | Should -Be 0 Is-ContainerRunning $global:AGENT_CONTAINER | Should -BeTrue $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "logs $global:AGENT_CONTAINER" @@ -204,4 +203,4 @@ Describe "[$global:JDK $global:FLAVOR] passing JVM options (slow test)" { Cleanup("nmap") CleanupNetwork("jnlp-network") } -} \ No newline at end of file +}