@@ -206,16 +206,6 @@ public void isIncluded() {
206206 assertTrue (substringVersionConfig .isIncluded (SUBSTRING_INCLUDED_VERSIONS_1 ));
207207 assertTrue (substringVersionConfig .isIncluded (SUBSTRING_INCLUDED_VERSIONS_2 ));
208208
209- assertFalse (nullVersionConfig .isIncluded ("" ));
210- assertFalse (oneVersionConfig .isIncluded ("" ));
211- assertFalse (multiVersionConfig .isIncluded ("" ));
212- assertFalse (substringVersionConfig .isIncluded ("" ));
213-
214- assertFalse (nullVersionConfig .isIncluded (null ));
215- assertFalse (oneVersionConfig .isIncluded (null ));
216- assertFalse (multiVersionConfig .isIncluded (null ));
217- assertFalse (substringVersionConfig .isIncluded (null ));
218-
219209 }
220210
221211 @ Test
@@ -228,7 +218,7 @@ public void clearCache() throws Exception {
228218 new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
229219 config .setDefaultVersion ("master" );
230220 config .setImplicit (true );
231- config .setCachingConfiguration (new LibraryCachingConfiguration (30 , null , "master" ));
221+ config .setCachingConfiguration (new LibraryCachingConfiguration (30 , null , null ));
232222 GlobalLibraries .get ().getLibraries ().add (config );
233223 // Run build and check that cache gets created.
234224 WorkflowJob p = r .createProject (WorkflowJob .class );
@@ -274,4 +264,43 @@ public void clearCacheConflict() throws Exception {
274264 assertThat (new File (cache .withSuffix ("-name.txt" ).getRemote ()), not (anExistingFile ()));
275265 }
276266
267+ @ Issue ("JENKINS-69135" ) //"Versions to include" feature for caching
268+ @ Test
269+ public void clearCacheIncludedVersion () throws Exception {
270+ sampleRepo .init ();
271+ sampleRepo .write ("vars/foo.groovy" , "def call() { echo 'foo' }" );
272+ sampleRepo .git ("add" , "vars" );
273+ sampleRepo .git ("commit" , "--message=init" );
274+ sampleRepo .git ("branch" , "test/include" );
275+ LibraryConfiguration config = new LibraryConfiguration ("library" ,
276+ new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
277+ config .setDefaultVersion ("master" );
278+ config .setAllowVersionOverride (true );
279+ config .setImplicit (false );
280+ config .setCachingConfiguration (new LibraryCachingConfiguration (30 , "" , "test/include" ));
281+ GlobalLibraries .get ().getLibraries ().add (config );
282+ // Run build and check that cache gets created.
283+ WorkflowJob p = r .createProject (WorkflowJob .class );
284+ p .setDefinition (new CpsFlowDefinition ("library identifier: 'library', changelog:false\n \n foo()" , true ));
285+ WorkflowRun b = r .buildAndAssertSuccess (p );
286+ WorkflowJob p2 = r .createProject (WorkflowJob .class );
287+ p2 .setDefinition (new CpsFlowDefinition ("library identifier: 'library@test/include', changelog:false\n \n foo()" , true ));
288+ WorkflowRun b2 = r .buildAndAssertSuccess (p2 );
289+ LibrariesAction action = b .getAction (LibrariesAction .class );
290+ LibraryRecord record = action .getLibraries ().get (0 );
291+ LibrariesAction action2 = b2 .getAction (LibrariesAction .class );
292+ LibraryRecord record2 = action2 .getLibraries ().get (0 );
293+ FilePath cache = LibraryCachingConfiguration .getGlobalLibrariesCacheDir ().child (record .getDirectoryName ());
294+ FilePath cache2 = LibraryCachingConfiguration .getGlobalLibrariesCacheDir ().child (record2 .getDirectoryName ());
295+ assertThat (new File (cache .getRemote ()), not (anExistingDirectory ()));
296+ assertThat (new File (cache .withSuffix ("-name.txt" ).getRemote ()), not (anExistingFile ()));
297+ assertThat (new File (cache2 .getRemote ()), anExistingDirectory ());
298+ assertThat (new File (cache2 .withSuffix ("-name.txt" ).getRemote ()), anExistingFile ());
299+ // Clears cache for the entire library, until the "Delete specific cache version" feature in merged
300+ // Clear the cache. TODO: Would be more realistic to set up security and use WebClient.
301+ ExtensionList .lookupSingleton (LibraryCachingConfiguration .DescriptorImpl .class ).doClearCache ("library" , false );
302+ assertThat (new File (cache2 .getRemote ()), not (anExistingDirectory ()));
303+ assertThat (new File (cache2 .withSuffix ("-name.txt" ).getRemote ()), not (anExistingFile ()));
304+ }
305+
277306}
0 commit comments