Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListTestCommands.java update to return structured map #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading