@@ -31,13 +31,11 @@ class PipelineWorkspaceTest {
3131 println (result)
3232
3333 // Verify it contains the runtime check
34- assertTrue(result.contains(" if (env.BRANCH_NAME)" ), " Should check for BRANCH_NAME" )
35- assertTrue(result.contains(" def rootDir = new File(env.WORKSPACE).parentFile.parent" ))
36- assertTrue(result.contains(" def safeBranch = (env.BRANCH_NAME ?: 'unknown').replaceAll(/[^A-Za-z0-9._-]/, '_')" ))
37- assertTrue(result.contains(" def customPath" ))
38- assertTrue(result.contains(" ws(customPath)" ))
39- assertTrue(result.contains(" checkout scm" ))
40- assertTrue(result.contains(" else {" ), " Should have else block for non-multibranch" )
34+ assertTrue(result.contains(" if (env.BRANCH_NAME)" ), " Should check for BRANCH_NAME to detect multibranch" )
35+ assertTrue(result.contains(" def decodedJobName = java.net.URLDecoder.decode(env.JOB_NAME, 'UTF-8')" ), " Should decode URL-encoded job name" )
36+ assertTrue(result.contains(" def safeJobName = decodedJobName.replaceAll(/[^A-Za-z0-9._-]/, '_')" ), " Should sanitize job name" )
37+ assertTrue(result.contains(" customWorkspacePath" ), " Should define customWorkspacePath" )
38+ assertTrue(result.contains(" customWorkspace customWorkspacePath" ), " Should use customWorkspacePath in agent" )
4139 }
4240
4341 @Test
@@ -61,9 +59,8 @@ class PipelineWorkspaceTest {
6159 println (result)
6260
6361 // Verify it uses custom workspace directly
64- assertTrue(result.contains(" def customPath = \" /my/custom/workspace\" " ))
65- assertTrue(result.contains(" ws(customPath)" ))
66- assertTrue(result.contains(" checkout scm" ))
62+ assertTrue(result.contains(" def customWorkspacePath = \" /my/custom/workspace\" " ), " Should define customWorkspacePath with custom value" )
63+ assertTrue(result.contains(" customWorkspace customWorkspacePath" ), " Should use customWorkspacePath in agent" )
6764 assertTrue(! result.contains(" if (env.BRANCH_NAME)" ), " Should NOT check for BRANCH_NAME when custom workspace is set" )
6865 }
6966
@@ -87,10 +84,9 @@ class PipelineWorkspaceTest {
8784 println (" \n === Generated Jenkinsfile with useMultibranchWorkspace=false ===" )
8885 println (result)
8986
90- // Verify it doesn't use any workspace wrapping
91- assertTrue(! result.contains(" ws(" ), " Should NOT use ws() wrapper" )
92- assertTrue(! result.contains(" customPath" ), " Should NOT have customPath" )
93- assertTrue(! result.contains(" checkout scm" ), " Should NOT have checkout scm" )
87+ // Verify it doesn't use any custom workspace logic
88+ assertTrue(! result.contains(" customWorkspacePath" ), " Should NOT have customWorkspacePath" )
89+ assertTrue(! result.contains(" if (env.BRANCH_NAME)" ), " Should NOT check for BRANCH_NAME" )
9490 assertTrue(result.contains(" stages {" ), " Should have stages block directly" )
9591 }
9692}
0 commit comments