From d638c18ffdf3331e02724f6d206ccae23b50e4c6 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Wed, 3 May 2023 17:31:23 -0400 Subject: [PATCH] Remove duplicate info from create/update reserved list command output (#2020) It was repeating the domain label twice for every reserved list entry. It used to look like this: baddies=baddies,FULLY_BLOCKED --- .../tools/CreateOrUpdateReservedListCommand.java | 9 +++++++++ .../registry/tools/CreateReservedListCommand.java | 8 ++------ .../registry/tools/UpdateReservedListCommand.java | 15 ++++----------- .../tools/CreateReservedListCommandTest.java | 6 +++--- .../tools/UpdateReservedListCommandTest.java | 3 +++ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/google/registry/tools/CreateOrUpdateReservedListCommand.java b/core/src/main/java/google/registry/tools/CreateOrUpdateReservedListCommand.java index 58229bc7d..c8bfe4a03 100644 --- a/core/src/main/java/google/registry/tools/CreateOrUpdateReservedListCommand.java +++ b/core/src/main/java/google/registry/tools/CreateOrUpdateReservedListCommand.java @@ -20,6 +20,7 @@ import google.registry.model.tld.label.ReservedList; import google.registry.model.tld.label.ReservedListDao; import google.registry.tools.params.PathParameter; import java.nio.file.Path; +import java.util.stream.Collectors; import javax.annotation.Nullable; /** @@ -69,4 +70,12 @@ public abstract class CreateOrUpdateReservedListCommand extends ConfirmingComman } return message; } + + String outputReservedListEntries(ReservedList rl) { + return "[" + + rl.getReservedListEntries().values().stream() + .map(rle -> String.format("(%s)", rle.toString())) + .collect(Collectors.joining(", ")) + + "]"; + } } diff --git a/core/src/main/java/google/registry/tools/CreateReservedListCommand.java b/core/src/main/java/google/registry/tools/CreateReservedListCommand.java index 602d461ef..5079aa09f 100644 --- a/core/src/main/java/google/registry/tools/CreateReservedListCommand.java +++ b/core/src/main/java/google/registry/tools/CreateReservedListCommand.java @@ -28,7 +28,6 @@ import com.google.common.base.Strings; import google.registry.model.tld.label.ReservedList; import java.nio.file.Files; import java.util.List; -import java.util.stream.Collectors; import org.joda.time.DateTime; /** Command to create a {@link ReservedList}. */ @@ -64,11 +63,8 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand .setCreationTimestamp(now) .build(); - String entries = - reservedList.getReservedListEntries().entrySet().stream() - .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())) - .collect(Collectors.joining(", ")); - return String.format("%s\nreservedListMap={%s}\n", reservedList, entries); + return String.format( + "%s\nreservedListMap=%s\n", reservedList, outputReservedListEntries(reservedList)); } private static void validateListName(String name) { diff --git a/core/src/main/java/google/registry/tools/UpdateReservedListCommand.java b/core/src/main/java/google/registry/tools/UpdateReservedListCommand.java index cd060f7ff..5f1e3bf3a 100644 --- a/core/src/main/java/google/registry/tools/UpdateReservedListCommand.java +++ b/core/src/main/java/google/registry/tools/UpdateReservedListCommand.java @@ -22,7 +22,6 @@ import com.google.common.base.Strings; import google.registry.model.tld.label.ReservedList; import java.nio.file.Files; import java.util.List; -import java.util.stream.Collectors; /** Command to safely update {@link ReservedList}. */ @Parameters(separators = " =", commandDescription = "Update a ReservedList.") @@ -52,17 +51,11 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand if (!existingReservedList .getReservedListEntries() .equals(reservedList.getReservedListEntries())) { - String oldEntries = - existingReservedList.getReservedListEntries().entrySet().stream() - .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())) - .collect(Collectors.joining(", ")); - String newEntries = - reservedList.getReservedListEntries().entrySet().stream() - .map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())) - .collect(Collectors.joining(", ")); return String.format( - "Update reserved list for %s?\nOld List: %s\n New List: %s", - name, oldEntries, newEntries); + "Update reserved list for %s?\nOld list: %s\n New list: %s", + name, + outputReservedListEntries(existingReservedList), + outputReservedListEntries(reservedList)); } return "No entity changes to apply."; } diff --git a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java index 4e3e559f0..e83fb3f52 100644 --- a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java @@ -190,8 +190,8 @@ class CreateReservedListCommandTest command.init(); assertThat(command.prompt()) .contains( - "reservedListMap={baddies=baddies,FULLY_BLOCKED, " - + "ford=ford,FULLY_BLOCKED # random comment}"); + "reservedListMap=[(baddies,FULLY_BLOCKED), " + + "(ford,FULLY_BLOCKED # random comment)]"); } @Test @@ -201,6 +201,6 @@ class CreateReservedListCommandTest CreateReservedListCommand command = new CreateReservedListCommand(); command.input = tmpPath; command.init(); - assertThat(command.prompt()).contains("reservedListMap={}"); + assertThat(command.prompt()).contains("reservedListMap=[]"); } } diff --git a/core/src/test/java/google/registry/tools/UpdateReservedListCommandTest.java b/core/src/test/java/google/registry/tools/UpdateReservedListCommandTest.java index 1f5f8ec08..46442238a 100644 --- a/core/src/test/java/google/registry/tools/UpdateReservedListCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateReservedListCommandTest.java @@ -130,5 +130,8 @@ class UpdateReservedListCommandTest command.init(); assertThat(command.prompt()).contains("Update reserved list for xn--q9jyb4c_common-reserved?"); + assertThat(command.prompt()).contains("Old list: [(helicopter,FULLY_BLOCKED)]"); + assertThat(command.prompt()) + .contains("New list: [(baddies,FULLY_BLOCKED), (ford,FULLY_BLOCKED # random comment)]"); } }