Skip to content

Commit

Permalink
UT improvement : Check that symlinks resources are preserved during g…
Browse files Browse the repository at this point in the history
…it clone
  • Loading branch information
rfscholte committed Dec 21, 2018
2 parents 4c1e7b2 + 7bd193a commit cbf2a52
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
Expand Up @@ -20,17 +20,22 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

/**
* Base class for testcases doing tests with files.
Expand All @@ -40,6 +45,9 @@
public class DirectoryScannerTest
extends FileBasedTestCase
{
@Rule
public TestName name = new TestName();

private static String testDir = getTestDirectory().getPath();

@Test
Expand Down Expand Up @@ -118,6 +126,47 @@ private void createTestFiles()
this.createFile( new File( testDir + "/scanner4.dat" ), 0 );
this.createFile( new File( testDir + "/scanner5.dat" ), 0 );
}

/**
* Check if 'src/test/resources/symlinks/src/sym*' test files (start with 'sym') exist and are symlinks.<br>
* On some OS (like Windows 10), the 'git clone' requires to be executed with admin permissions and the
* 'core.symlinks=true' git option.
*
* @return true If files here and symlinks, false otherwise
*/
private boolean checkTestFilesSymlinks()
{
File symlinksDirectory = new File( "src/test/resources/symlinks/src" );
try
{
List<String> symlinks =
FileUtils.getFileAndDirectoryNames( symlinksDirectory, "sym*", null, true, true, true, true );
if ( symlinks.isEmpty() )
{
throw new IOException( "Symlinks files/directories are not present" );
}
for ( String symLink : symlinks )
{
if ( !Files.isSymbolicLink( Paths.get( symLink ) ) )
{
throw new IOException( String.format( "Path is not a symlink: %s", symLink ) );
}
}
return true;
}
catch ( IOException e )
{
System.err.println( String.format( "The unit test '%s.%s' will be skipped, reason: %s",
this.getClass().getSimpleName(), name.getMethodName(),
e.getMessage() ) );
System.out.println( String.format( "This test requires symlinks files in '%s' directory.",
symlinksDirectory.getPath() ) );
System.out.println( "On some OS (like Windows 10), files are present only if the clone/checkout is done"
+ " in administrator mode, and correct (symlinks and not flat file/directory)"
+ " if symlinks option are used (for git: git clone -c core.symlinks=true [url])" );
return false;
}
}

@Test
public void testGeneral()
Expand Down Expand Up @@ -158,6 +207,8 @@ public void testIncludesExcludesWithWhiteSpaces()
@Test
public void testFollowSymlinksFalse()
{
assumeTrue( checkTestFilesSymlinks() );

DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) );
ds.setFollowSymlinks( false );
Expand Down Expand Up @@ -190,6 +241,8 @@ private void assertAlwaysIncluded( List<String> included )
@Test
public void testFollowSymlinks()
{
assumeTrue( checkTestFilesSymlinks() );

DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) );
ds.setFollowSymlinks( true );
Expand Down Expand Up @@ -428,11 +481,7 @@ public void testRegexWithSlashInsideCharacterClass()
public void testIsSymbolicLink()
throws IOException
{
// TODO: Uncomment when PR #25 merged
// if ( !checkTestFilesSymlinks() )
// {
// return;
// }
assumeTrue( checkTestFilesSymlinks() );

final File directory = new File( "src/test/resources/symlinks/src" );
DirectoryScanner ds = new DirectoryScanner();
Expand All @@ -446,11 +495,7 @@ public void testIsSymbolicLink()
public void testIsParentSymbolicLink()
throws IOException
{
// TODO: Uncomment when PR #25 merged
// if ( !checkTestFilesSymlinks() )
// {
// return;
// }
assumeTrue( checkTestFilesSymlinks() );

final File directory = new File( "src/test/resources/symlinks/src" );
DirectoryScanner ds = new DirectoryScanner();
Expand Down

0 comments on commit cbf2a52

Please sign in to comment.