@@ -61,31 +61,57 @@ public class LibraryCachingConfigurationTest {
61
61
private static int NO_REFRESH_TIME_MINUTES = 0 ;
62
62
63
63
private static String NULL_EXCLUDED_VERSION = null ;
64
+ private static String NULL_INCLUDED_VERSION = null ;
65
+
64
66
private static String ONE_EXCLUDED_VERSION = "branch-1" ;
65
67
68
+ private static String ONE_INCLUDED_VERSION = "branch-1i" ;
69
+
70
+
66
71
private static String MULTIPLE_EXCLUDED_VERSIONS_1 = "main" ;
72
+
73
+ private static String MULTIPLE_INCLUDED_VERSIONS_1 = "master" ;
74
+
67
75
private static String MULTIPLE_EXCLUDED_VERSIONS_2 = "branch-2" ;
76
+
77
+ private static String MULTIPLE_INCLUDED_VERSIONS_2 = "branch-2i" ;
78
+
68
79
private static String MULTIPLE_EXCLUDED_VERSIONS_3 = "branch-3" ;
80
+ private static String MULTIPLE_INCLUDED_VERSIONS_3 = "branch-3i" ;
81
+
69
82
70
83
private static String SUBSTRING_EXCLUDED_VERSIONS_1 = "feature/test-substring-exclude" ;
84
+
85
+ private static String SUBSTRING_INCLUDED_VERSIONS_1 = "feature_include/test-substring" ;
86
+
71
87
private static String SUBSTRING_EXCLUDED_VERSIONS_2 = "test-other-substring-exclude" ;
88
+ private static String SUBSTRING_INCLUDED_VERSIONS_2 = "test-other-substring-include" ;
89
+
72
90
73
91
private static String MULTIPLE_EXCLUDED_VERSIONS =
74
92
MULTIPLE_EXCLUDED_VERSIONS_1 + " " +
75
93
MULTIPLE_EXCLUDED_VERSIONS_2 + " " +
76
94
MULTIPLE_EXCLUDED_VERSIONS_3 ;
77
95
96
+ private static String MULTIPLE_INCLUDED_VERSIONS =
97
+ MULTIPLE_INCLUDED_VERSIONS_1 + " " +
98
+ MULTIPLE_INCLUDED_VERSIONS_2 + " " +
99
+ MULTIPLE_INCLUDED_VERSIONS_3 ;
100
+
78
101
private static String SUBSTRING_EXCLUDED_VERSIONS =
79
102
"feature/ other-substring" ;
80
103
104
+ private static String SUBSTRING_INCLUDED_VERSIONS =
105
+ "feature_include/ other-substring" ;
106
+
81
107
private static String NEVER_EXCLUDED_VERSION = "never-excluded-version" ;
82
108
83
109
@ Before
84
110
public void createCachingConfiguration () {
85
- nullVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , NULL_EXCLUDED_VERSION );
86
- oneVersionConfig = new LibraryCachingConfiguration (NO_REFRESH_TIME_MINUTES , ONE_EXCLUDED_VERSION );
87
- multiVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , MULTIPLE_EXCLUDED_VERSIONS );
88
- substringVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , SUBSTRING_EXCLUDED_VERSIONS );
111
+ nullVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , NULL_EXCLUDED_VERSION , NULL_INCLUDED_VERSION );
112
+ oneVersionConfig = new LibraryCachingConfiguration (NO_REFRESH_TIME_MINUTES , ONE_EXCLUDED_VERSION , ONE_INCLUDED_VERSION );
113
+ multiVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , MULTIPLE_EXCLUDED_VERSIONS , MULTIPLE_INCLUDED_VERSIONS );
114
+ substringVersionConfig = new LibraryCachingConfiguration (REFRESH_TIME_MINUTES , SUBSTRING_EXCLUDED_VERSIONS , SUBSTRING_INCLUDED_VERSIONS );
89
115
}
90
116
91
117
@ Issue ("JENKINS-66045" ) // NPE getting excluded versions
@@ -125,6 +151,15 @@ public void getExcludedVersionsStr() {
125
151
assertThat (substringVersionConfig .getExcludedVersionsStr (), is (SUBSTRING_EXCLUDED_VERSIONS ));
126
152
}
127
153
154
+ @ Test
155
+ @ WithoutJenkins
156
+ public void getIncludedVersionsStr () {
157
+ assertThat (nullVersionConfig .getIncludedVersionsStr (), is (NULL_INCLUDED_VERSION ));
158
+ assertThat (oneVersionConfig .getIncludedVersionsStr (), is (ONE_INCLUDED_VERSION ));
159
+ assertThat (multiVersionConfig .getIncludedVersionsStr (), is (MULTIPLE_INCLUDED_VERSIONS ));
160
+ assertThat (substringVersionConfig .getIncludedVersionsStr (), is (SUBSTRING_INCLUDED_VERSIONS ));
161
+ }
162
+
128
163
@ Test
129
164
@ WithoutJenkins
130
165
public void isExcluded () {
@@ -155,6 +190,23 @@ public void isExcluded() {
155
190
assertFalse (substringVersionConfig .isExcluded (null ));
156
191
}
157
192
193
+ @ Test
194
+ @ WithoutJenkins
195
+ public void isIncluded () {
196
+ assertFalse (nullVersionConfig .isIncluded (NULL_INCLUDED_VERSION ));
197
+ assertFalse (nullVersionConfig .isIncluded ("" ));
198
+
199
+ assertTrue (oneVersionConfig .isIncluded (ONE_INCLUDED_VERSION ));
200
+
201
+ assertTrue (multiVersionConfig .isIncluded (MULTIPLE_INCLUDED_VERSIONS_1 ));
202
+ assertTrue (multiVersionConfig .isIncluded (MULTIPLE_INCLUDED_VERSIONS_2 ));
203
+ assertTrue (multiVersionConfig .isIncluded (MULTIPLE_INCLUDED_VERSIONS_3 ));
204
+
205
+ assertTrue (substringVersionConfig .isIncluded (SUBSTRING_INCLUDED_VERSIONS_1 ));
206
+ assertTrue (substringVersionConfig .isIncluded (SUBSTRING_INCLUDED_VERSIONS_2 ));
207
+
208
+ }
209
+
158
210
@ Test
159
211
public void clearCache () throws Exception {
160
212
sampleRepo .init ();
@@ -165,7 +217,7 @@ public void clearCache() throws Exception {
165
217
new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
166
218
config .setDefaultVersion ("master" );
167
219
config .setImplicit (true );
168
- config .setCachingConfiguration (new LibraryCachingConfiguration (30 , null ));
220
+ config .setCachingConfiguration (new LibraryCachingConfiguration (30 , null , "master" ));
169
221
GlobalLibraries .get ().getLibraries ().add (config );
170
222
// Run build and check that cache gets created.
171
223
WorkflowJob p = r .createProject (WorkflowJob .class );
@@ -182,4 +234,29 @@ public void clearCache() throws Exception {
182
234
assertThat (new File (cache .withSuffix ("-name.txt" ).getRemote ()), not (anExistingFile ()));
183
235
}
184
236
237
+ @ Test
238
+ public void clearCacheConflict () throws Exception {
239
+ sampleRepo .init ();
240
+ sampleRepo .write ("vars/foo.groovy" , "def call() { echo 'foo' }" );
241
+ sampleRepo .git ("add" , "vars" );
242
+ sampleRepo .git ("commit" , "--message=init" );
243
+ LibraryConfiguration config = new LibraryConfiguration ("library" ,
244
+ new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
245
+ config .setDefaultVersion ("master" );
246
+ config .setImplicit (true );
247
+ // Same version specified in both include and exclude version
248
+ //Exclude takes precedence
249
+ config .setCachingConfiguration (new LibraryCachingConfiguration (30 , "master" , "master" ));
250
+ GlobalLibraries .get ().getLibraries ().add (config );
251
+ // Run build and check that cache gets created.
252
+ WorkflowJob p = r .createProject (WorkflowJob .class );
253
+ p .setDefinition (new CpsFlowDefinition ("foo()" , true ));
254
+ WorkflowRun b = r .buildAndAssertSuccess (p );
255
+ LibrariesAction action = b .getAction (LibrariesAction .class );
256
+ LibraryRecord record = action .getLibraries ().get (0 );
257
+ FilePath cache = LibraryCachingConfiguration .getGlobalLibrariesCacheDir ().child (record .getDirectoryName ());
258
+ assertThat (new File (cache .getRemote ()), not (anExistingDirectory ()));
259
+ assertThat (new File (cache .withSuffix ("-name.txt" ).getRemote ()), not (anExistingFile ()));
260
+ }
261
+
185
262
}
0 commit comments