use of io.confluent.ksql.test.parser.SqlTestLoader.SqlTest in project ksql by confluentinc.
the class SqlTestLoader method loadTest.
/**
* @param path a single sql test file, containing possibly many tests
*
* @return the list of tests to run
*/
public List<SqlTest> loadTest(final Path path) throws IOException {
final ImmutableList.Builder<SqlTest> builder = ImmutableList.builder();
List<TestStatement> statements = null;
String name = null;
final SqlTestReader reader = SqlTestReader.of(path);
while (reader.hasNext()) {
final TestStatement statement = reader.next();
final Optional<String> nextName = statement.consumeDirective(directive -> directive.getType() == Type.TEST ? directive.getContents() : null);
if (nextName.isPresent()) {
// flush the previous test
if (statements != null) {
builder.add(new SqlTest(path, name, statements));
}
statements = new ArrayList<>();
name = nextName.get();
} else if (statements == null) {
throw new KsqlTestException(statement, path, "Exepcted test to start with --@test.");
}
statements.add(statement);
}
builder.add(new SqlTest(path, name, statements));
return builder.build().stream().filter(shouldRun).collect(ImmutableList.toImmutableList());
}
use of io.confluent.ksql.test.parser.SqlTestLoader.SqlTest in project ksql by confluentinc.
the class SqlTestLoader method load.
@Override
public Stream<SqlTest> load() throws IOException {
final List<Path> files = Files.find(path, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile()).collect(Collectors.toList());
final ImmutableList.Builder<SqlTest> builder = ImmutableList.builder();
final List<String> whiteList = TestLoader.getWhiteList();
for (final Path file : files) {
if (whiteList.isEmpty() || whiteList.stream().anyMatch(file::endsWith)) {
builder.addAll(loadTest(file));
}
}
return builder.build().stream();
}
Aggregations