Skip to content

Commit

Permalink
allow empty results directories (fixes #312, via #426)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jun 26, 2017
1 parent 074dd20 commit cf31d63
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.beust.jcommander.Parameter;
import io.qameta.allure.convert.PathConverter;
import io.qameta.allure.validator.DirectoryExistsValidator;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -21,8 +20,7 @@ public class ResultsOptions {

@Parameter(
description = "The directories with allure results",
converter = PathConverter.class,
validateWith = DirectoryExistsValidator.class
converter = PathConverter.class
)
private List<Path> resultsDirectories = new ArrayList<>(singletonList(Paths.get("allure-results")));

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,10 @@ public void shouldParseQuietFlag() throws Exception {
}

@Test
public void shouldValidateResultsDirectoryExists() throws Exception {
public void shouldAllowResultsDirectoriesThatNotExists() throws Exception {
final Optional<ExitCode> exitCode = commandLine.parse(GENERATE_COMMAND, randomString(), randomString());
assertThat(exitCode)
.isPresent()
.hasValue(ExitCode.ARGUMENT_PARSING_ERROR);
}

@Test
public void shouldNotFailIfResultsAreRegularFile() throws Exception {
final Path results = folder.newFile().toPath();
final Optional<ExitCode> exitCode = commandLine.parse(GENERATE_COMMAND, results.toString());
assertThat(exitCode)
.isPresent()
.hasValue(ExitCode.ARGUMENT_PARSING_ERROR);
.isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import io.qameta.allure.core.Configuration;
import io.qameta.allure.core.LaunchResults;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -14,6 +17,8 @@
*/
public class ReportGenerator {

private static final Logger LOGGER = LoggerFactory.getLogger(ReportGenerator.class);

private final Configuration configuration;

public ReportGenerator(final Configuration configuration) {
Expand Down Expand Up @@ -44,9 +49,21 @@ public void generate(final Path outputDirectory, final Path... resultsDirectorie

private void generate(final Path outputDirectory, final Stream<Path> resultsDirectories) throws IOException {
final List<LaunchResults> results = resultsDirectories
.filter(this::isValidResultsDirectory)
.map(this::readResults)
.collect(Collectors.toList());
aggregate(results, outputDirectory);
}

private boolean isValidResultsDirectory(final Path resultsDirectory) {
if (Files.notExists(resultsDirectory)) {
LOGGER.warn("{} does not exists", resultsDirectory);
return false;
}
if (!Files.isDirectory(resultsDirectory)) {
LOGGER.warn("{} is not a directory", resultsDirectory);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.qameta.allure;

import io.qameta.allure.core.Configuration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.nio.file.Path;

/**
* @author charlie (Dmitry Baev).
*/
public class EmptyResultsTest {

@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Test
public void shouldAllowEmptyResultsDirectory() throws Exception {
final Path resultsDirectory = folder.newFolder().toPath();
final Path outputDirectory = folder.newFolder().toPath();
final Configuration configuration = new ConfigurationBuilder().useDefault().build();
final ReportGenerator generator = new ReportGenerator(configuration);

generator.generate(outputDirectory, resultsDirectory);
}

@Test
public void shouldAllowNonExistsResultsDirectory() throws Exception {
final Path resultsDirectory = folder.newFolder().toPath().resolve("some-dir");
final Path outputDirectory = folder.newFolder().toPath();
final Configuration configuration = new ConfigurationBuilder().useDefault().build();
final ReportGenerator generator = new ReportGenerator(configuration);

generator.generate(outputDirectory, resultsDirectory);
}

@Test
public void shouldAllowRegularFileAsResultsDirectory() throws Exception {
final Path resultsDirectory = folder.newFile().toPath();
final Path outputDirectory = folder.newFolder().toPath();
final Configuration configuration = new ConfigurationBuilder().useDefault().build();
final ReportGenerator generator = new ReportGenerator(configuration);

generator.generate(outputDirectory, resultsDirectory);
}
}

0 comments on commit cf31d63

Please # to comment.