Skip to content

Commit

Permalink
Merge pull request #14 from D3ryk/validVMsOnIndexPage
Browse files Browse the repository at this point in the history
Bugfix implementation + modification of unit test
  • Loading branch information
sparkoo authored Aug 4, 2017
2 parents cf79176 + 3144f30 commit 8dce89f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public FilesystemBoxRepository(AppProperties appProperties, HashService hashServ
@Override
public List<String> getBoxes() {
return Arrays.stream(boxHome.listFiles(File::isDirectory))
.filter(this::containsValidBoxFile)
.map(File::getName)
.sorted()
.collect(Collectors.toList());
Expand Down Expand Up @@ -82,8 +83,9 @@ private Map<String, List<File>> groupBoxFilesByVersion(File boxDir) {

private boolean validateFilename(File boxFile) {
String filename = boxFile.getName();
List<String> parsedFilename = Arrays.asList(filename.split("_"));
if (parsedFilename.size() != 3) {
File parentDir = boxFile.getParentFile();

if (!filename.matches(parentDir.getName() + "_(\\d+)_(\\w+)\\.box")) {
LOG.warn("box file [{}] has wrong name. must be in format ${name}_${version}_${provider}.box", filename);
return false;
}
Expand Down Expand Up @@ -132,4 +134,9 @@ private BoxProvider createBoxProviderFromFile(File file) {
hashService.getChecksum(file.getAbsolutePath())
);
}

private boolean containsValidBoxFile(File file) {
File[] files = file.listFiles(this::validateFilename);
return files.length > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Optional;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

@SpringBootTest
Expand Down Expand Up @@ -168,7 +169,8 @@ public void givenValidRepositoryWithBoxes_whenIndex_thenGetValidBoxes() {
BoxRepository boxRepository = new FilesystemBoxRepository(testAppProperties, new NoopHashService());

List<String> boxes = boxRepository.getBoxes();
assertTrue(boxes.containsAll(Arrays.asList("f25", "f26", "f27", "f28", "f29")));
assertTrue(boxes.containsAll(Arrays.asList("f25", "f26", "f28", "f29")));
assertFalse(boxes.containsAll(Arrays.asList("f27")));
}

private String composePath(String boxName, String version, String provider) {
Expand Down

0 comments on commit 8dce89f

Please sign in to comment.