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
This commit is contained in:
Ben McIlwain 2023-05-03 17:31:23 -04:00 committed by GitHub
parent cbffc454b5
commit d638c18ffd
5 changed files with 21 additions and 20 deletions

View file

@ -20,6 +20,7 @@ import google.registry.model.tld.label.ReservedList;
import google.registry.model.tld.label.ReservedListDao; import google.registry.model.tld.label.ReservedListDao;
import google.registry.tools.params.PathParameter; import google.registry.tools.params.PathParameter;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -69,4 +70,12 @@ public abstract class CreateOrUpdateReservedListCommand extends ConfirmingComman
} }
return message; return message;
} }
String outputReservedListEntries(ReservedList rl) {
return "["
+ rl.getReservedListEntries().values().stream()
.map(rle -> String.format("(%s)", rle.toString()))
.collect(Collectors.joining(", "))
+ "]";
}
} }

View file

@ -28,7 +28,6 @@ import com.google.common.base.Strings;
import google.registry.model.tld.label.ReservedList; import google.registry.model.tld.label.ReservedList;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** Command to create a {@link ReservedList}. */ /** Command to create a {@link ReservedList}. */
@ -64,11 +63,8 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand
.setCreationTimestamp(now) .setCreationTimestamp(now)
.build(); .build();
String entries = return String.format(
reservedList.getReservedListEntries().entrySet().stream() "%s\nreservedListMap=%s\n", reservedList, outputReservedListEntries(reservedList));
.map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue()))
.collect(Collectors.joining(", "));
return String.format("%s\nreservedListMap={%s}\n", reservedList, entries);
} }
private static void validateListName(String name) { private static void validateListName(String name) {

View file

@ -22,7 +22,6 @@ import com.google.common.base.Strings;
import google.registry.model.tld.label.ReservedList; import google.registry.model.tld.label.ReservedList;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** Command to safely update {@link ReservedList}. */ /** Command to safely update {@link ReservedList}. */
@Parameters(separators = " =", commandDescription = "Update a ReservedList.") @Parameters(separators = " =", commandDescription = "Update a ReservedList.")
@ -52,17 +51,11 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand
if (!existingReservedList if (!existingReservedList
.getReservedListEntries() .getReservedListEntries()
.equals(reservedList.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( return String.format(
"Update reserved list for %s?\nOld List: %s\n New List: %s", "Update reserved list for %s?\nOld list: %s\n New list: %s",
name, oldEntries, newEntries); name,
outputReservedListEntries(existingReservedList),
outputReservedListEntries(reservedList));
} }
return "No entity changes to apply."; return "No entity changes to apply.";
} }

View file

@ -190,8 +190,8 @@ class CreateReservedListCommandTest
command.init(); command.init();
assertThat(command.prompt()) assertThat(command.prompt())
.contains( .contains(
"reservedListMap={baddies=baddies,FULLY_BLOCKED, " "reservedListMap=[(baddies,FULLY_BLOCKED), "
+ "ford=ford,FULLY_BLOCKED # random comment}"); + "(ford,FULLY_BLOCKED # random comment)]");
} }
@Test @Test
@ -201,6 +201,6 @@ class CreateReservedListCommandTest
CreateReservedListCommand command = new CreateReservedListCommand(); CreateReservedListCommand command = new CreateReservedListCommand();
command.input = tmpPath; command.input = tmpPath;
command.init(); command.init();
assertThat(command.prompt()).contains("reservedListMap={}"); assertThat(command.prompt()).contains("reservedListMap=[]");
} }
} }

View file

@ -130,5 +130,8 @@ class UpdateReservedListCommandTest
command.init(); command.init();
assertThat(command.prompt()).contains("Update reserved list for xn--q9jyb4c_common-reserved?"); 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)]");
} }
} }