1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-11-24 08:32:32 +02:00

seleniumExecuteTests: expose container metadata via env vars (#1170)

* inject container metadata via env vars to selenium

* set step-specific env var for uiVeri55ExecuteTests

* Revert "set step-specific env var for uiVeri55ExecuteTests"

This reverts commit 8deb39ac5b.

* remove env vars that indicate piper step

* remove env var to indicate execution through selenium step

Co-Authored-By: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* remove defaulting of docker env vars

Co-Authored-By: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* Update vars/karmaExecuteTests.groovy

Co-Authored-By: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
Maximilian Lenkeit 2020-02-13 02:09:08 -06:00 committed by GitHub
parent be03b3dfc1
commit 00b094d74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

@ -75,8 +75,10 @@ class KarmaExecuteTestsTest extends BasePiperTest {
assert expectedImage == seleniumParams.dockerImage
assert expectedOptions == seleniumParams.dockerOptions
assert expectedEnvVars.equals(seleniumParams.dockerEnvVars)
assert expectedWorkspace == seleniumParams.dockerWorkspace
expectedEnvVars.each { key, value ->
assert seleniumParams.dockerEnvVars[key] == value
}
}
@Test

View File

@ -39,6 +39,15 @@ class SeleniumExecuteTestsTest extends BasePiperTest {
@Test
void testExecuteSeleniumDefault() {
def expectedDefaultEnvVars = [
// following env vars are expected in JSON format
'PIPER_CONTAINER_PORT_MAPPING': '{"selenium/standalone-chrome":[{"containerPort":4444,"hostPort":4444}]}',
'PIPER_DOCKER_NAME': '"npm"',
'PIPER_DOCKER_IMAGE': '"node:lts-stretch"',
'PIPER_SIDECAR_NAME': '"selenium"',
'PIPER_SIDECAR_IMAGE': '"selenium/standalone-chrome"'
]
stepRule.step.seleniumExecuteTests(
script: nullScript,
juStabUtils: utils
@ -47,7 +56,6 @@ class SeleniumExecuteTestsTest extends BasePiperTest {
}
assertThat(bodyExecuted, is(true))
assertThat(dockerExecuteRule.dockerParams.containerPortMappings, is(['selenium/standalone-chrome': [[containerPort: 4444, hostPort: 4444]]]))
assertThat(dockerExecuteRule.dockerParams.dockerEnvVars, is(null))
assertThat(dockerExecuteRule.dockerParams.dockerImage, is('node:lts-stretch'))
assertThat(dockerExecuteRule.dockerParams.dockerName, is('npm'))
assertThat(dockerExecuteRule.dockerParams.dockerWorkspace, is('/home/node'))
@ -55,6 +63,9 @@ class SeleniumExecuteTestsTest extends BasePiperTest {
assertThat(dockerExecuteRule.dockerParams.sidecarImage, is('selenium/standalone-chrome'))
assertThat(dockerExecuteRule.dockerParams.sidecarName, is('selenium'))
assertThat(dockerExecuteRule.dockerParams.sidecarVolumeBind, is(['/dev/shm': '/dev/shm']))
expectedDefaultEnvVars.each { key, value ->
assert dockerExecuteRule.dockerParams.dockerEnvVars[key] == value
}
}
@Test
@ -80,8 +91,10 @@ class SeleniumExecuteTestsTest extends BasePiperTest {
assert expectedImage == dockerExecuteRule.dockerParams.dockerImage
assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions
assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars)
assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace
expectedEnvVars.each { key, value ->
assert dockerExecuteRule.dockerParams.dockerEnvVars[key] == value
}
}
@Test

View File

@ -5,6 +5,7 @@ import com.sap.piper.GenerateDocumentation
import com.sap.piper.GitUtils
import com.sap.piper.Utils
import com.sap.piper.k8s.ContainerMap
import groovy.json.JsonOutput
import groovy.transform.Field
import groovy.text.GStringTemplateEngine
@ -99,6 +100,14 @@ void call(Map parameters = [:], Closure body) {
stepParam1: parameters?.script == null
], config)
// Inject config via env vars so that scripts running inside selenium can respond to that
config.dockerEnvVars = config.dockerEnvVars ?: [:]
config.dockerEnvVars.PIPER_CONTAINER_PORT_MAPPING = new JsonOutput().toJson(config.containerPortMappings)
config.dockerEnvVars.PIPER_DOCKER_NAME = new JsonOutput().toJson(config.dockerName)
config.dockerEnvVars.PIPER_DOCKER_IMAGE = new JsonOutput().toJson(config.dockerImage)
config.dockerEnvVars.PIPER_SIDECAR_NAME = new JsonOutput().toJson(config.sidecarName)
config.dockerEnvVars.PIPER_SIDECAR_IMAGE = new JsonOutput().toJson(config.sidecarImage)
dockerExecute(
script: script,
containerPortMappings: config.containerPortMappings,