-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathTestLibraryAndScriptCaching.groovy
More file actions
71 lines (62 loc) · 2.5 KB
/
TestLibraryAndScriptCaching.groovy
File metadata and controls
71 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.lesfurets.jenkins
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.lesfurets.jenkins.unit.global.lib.LibraryLoader
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource
import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.jupiter.api.Assertions.assertNotEquals
class TestLibraryAndScriptCaching extends BasePipelineTest {
@Override
@BeforeEach
void setUp() throws Exception {
scriptRoots += 'src/test/jenkins'
super.setUp()
}
private final library = library().name('commons')
.defaultVersion('<notNeeded>')
.allowOverride(false)
.implicit(false)
.targetPath('<notNeeded>')
.retriever(projectSource(this.class.getResource('/libs/commons@master').getFile()))
.build()
@Test
void scriptCacheDisabled() {
def script1 = loadScript('job/exampleJob.jenkins')
helper.init()
def script2 = loadScript('job/exampleJob.jenkins')
assertNotEquals(script1.metaClass.theClass, script2.metaClass.theClass)
}
@Test
void scriptCacheEnabledDisabled() {
helper.withShouldCacheScriptsAndLibraries(true)
def script1 = loadScript('job/exampleJob.jenkins')
helper.init()
def script2 = loadScript('job/exampleJob.jenkins')
assertEquals(script1.metaClass.theClass, script2.metaClass.theClass)
}
@Test
void libraryCacheDisabled() {
helper.registerSharedLibrary(library)
helper.libLoader.loadLibrary(library.name)
def lib1 = LibraryLoader.libRecords.get("commons@<notNeeded>")
helper.init()
helper.registerSharedLibrary(library)
helper.libLoader.loadLibrary(library.name)
def lib2 = LibraryLoader.libRecords.get("commons@<notNeeded>")
assertNotEquals(lib1, lib2)
}
@Test
void libraryCacheEnabled() {
helper.withShouldCacheScriptsAndLibraries(true)
helper.registerSharedLibrary(library)
helper.libLoader.loadLibrary(library.name)
def lib1 = LibraryLoader.libRecords.get("commons@<notNeeded>")
helper.init()
helper.registerSharedLibrary(library)
helper.libLoader.loadLibrary(library.name)
def lib2 = LibraryLoader.libRecords.get("commons@<notNeeded>")
assertEquals(lib1, lib2)
}
}