Skip to content

Commit

Permalink
Updated ListTestsCommand.java to print a structured map of test names…
Browse files Browse the repository at this point in the history
… and associated tags rather than an arbitrary list of tags for the whole project when calling 'list --tags'.
  • Loading branch information
theonakfoor committed Sep 27, 2024
1 parent d364796 commit 59c2423
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,29 @@ public int listTests(List<ITestSuite> testSuits, OutputFormat format) throws Thr

public int listTags(List<ITestSuite> testSuits, OutputFormat format) throws Throwable {

Set<String> tags = new HashSet<String>();
Map<String, Map<String, Set<String>>> tests = new HashMap<>();
for (ITestSuite testSuite : testSuits) {
tags.addAll(testSuite.getTags());
Set<String> tagList = new HashSet<>();
tagList.addAll(testSuite.getTags());
for (ITest test : testSuite.getTests()) {
tags.addAll(test.getTags());
tagList.addAll(test.getTags());
}
Map<String, Set<String>> tags = new HashMap<>();
tags.put("tags", tagList);
tests.put(testSuite.getName(), tags);
}

switch (format) {
case JSON:
case json:
printTagsAsJson(tags);
printTagsAsJson(tests);
break;
case CSV:
case csv:
printTagsAsCsv(tags);
printTagsAsCsv(tests);
break;
default:
printTagsPretty(tags);
printTagsPretty(tests);
break;
}

Expand Down Expand Up @@ -215,17 +219,23 @@ private void printTestsPretty(List<ITestSuite> testSuits) {
System.out.println();
}

private void printTagsAsJson(Set<String> tags) {
private void printTagsAsJson(Map<String, Map<String, Set<String>>> tags) {
System.out.println(JsonOutput.toJson(tags));
}

private void printTagsAsCsv(Set<String> tags) {
System.out.println(String.join(",", tags));
private void printTagsAsCsv(Map<String, Map<String, Set<String>>> tags) {
for (Map.Entry<String, Map<String, Set<String>>> entry : tags.entrySet()) {
System.out.print(entry.getKey() + ",");
for(String tag : entry.getValue().get("tags")) {
System.out.print(tag + ",");
}
System.out.println();
}
}

private void printTagsPretty(Set<String> tags) {
for (String tag : tags) {
System.out.println(tag);
private void printTagsPretty(Map<String, Map<String, Set<String>>> tags) {
for (Map.Entry<String, Map<String, Set<String>>> entry : tags.entrySet()) {
System.out.println("Test: " + entry.getKey() + " Tags:" + entry.getValue().get("tags"));
}
}

Expand Down

0 comments on commit 59c2423

Please sign in to comment.