mirror of
https://github.com/google/nomulus
synced 2026-01-09 15:43:52 +00:00
Pretty-print reserved list updates in the CLI (#2226)
We shouldn't have to parse through every single entry to see what changed Note: we don't do this for premium lists because those can be HUGE and we don't want/need to load and display every entry. This was an explicit choice made in https://github.com/google/nomulus/pull/1482
This commit is contained in:
@@ -463,8 +463,7 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkReservedListValidityForTld(String tld, Set<String> reservedListNames)
|
||||
throws UnsupportedEncodingException {
|
||||
private void checkReservedListValidityForTld(String tld, Set<String> reservedListNames) {
|
||||
ImmutableList.Builder<String> builder = new ImmutableList.Builder<>();
|
||||
for (String reservedListName : reservedListNames) {
|
||||
if (!reservedListName.startsWith("common_") && !reservedListName.startsWith(tld + "_")) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
||||
import static google.registry.util.ListNamingUtils.convertFilePathToName;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
@@ -46,17 +47,27 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand
|
||||
.setReservedListMapFromLines(allLines)
|
||||
.setShouldPublish(shouldPublish);
|
||||
reservedList = updated.build();
|
||||
// only call stageEntityChange if there are changes in entries
|
||||
|
||||
if (!existingReservedList
|
||||
.getReservedListEntries()
|
||||
.equals(reservedList.getReservedListEntries())) {
|
||||
return String.format(
|
||||
"Update reserved list for %s?\nOld list: %s\n New list: %s",
|
||||
name,
|
||||
outputReservedListEntries(existingReservedList),
|
||||
outputReservedListEntries(reservedList));
|
||||
boolean shouldPublishChanged =
|
||||
existingReservedList.getShouldPublish() != reservedList.getShouldPublish();
|
||||
boolean reservedListEntriesChanged =
|
||||
!existingReservedList
|
||||
.getReservedListEntries()
|
||||
.equals(reservedList.getReservedListEntries());
|
||||
if (!shouldPublishChanged && !reservedListEntriesChanged) {
|
||||
return "No entity changes to apply.";
|
||||
}
|
||||
return "No entity changes to apply.";
|
||||
String result = String.format("Update reserved list for %s?\n", name);
|
||||
if (shouldPublishChanged) {
|
||||
result +=
|
||||
String.format(
|
||||
"shouldPublish: %s -> %s\n",
|
||||
existingReservedList.getShouldPublish(), reservedList.getShouldPublish());
|
||||
}
|
||||
if (reservedListEntriesChanged) {
|
||||
result +=
|
||||
prettyPrintEntityDeepDiff(
|
||||
existingReservedList.getReservedListEntries(), reservedList.getReservedListEntries());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
|
||||
.write("sdfgagmsdgs,sdfgsd\nasdf234tafgs,asdfaw\n\n");
|
||||
reservedTermsPath = reservedTermsFile.getPath();
|
||||
invalidReservedTermsPath = invalidReservedTermsFile.getPath();
|
||||
command.printStream = System.out;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -66,6 +66,8 @@ class UpdateReservedListCommandTest
|
||||
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
|
||||
ReservedList reservedList = ReservedList.get("xn--q9jyb4c_common-reserved").get();
|
||||
assertThat(reservedList.getShouldPublish()).isFalse();
|
||||
assertInStdout("Update reserved list for xn--q9jyb4c_common-reserved?");
|
||||
assertInStdout("shouldPublish: true -> false");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,6 +87,10 @@ class UpdateReservedListCommandTest
|
||||
assertThat(reservedList.getReservationInList("baddies")).hasValue(FULLY_BLOCKED);
|
||||
assertThat(reservedList.getReservationInList("ford")).hasValue(FULLY_BLOCKED);
|
||||
assertThat(reservedList.getReservationInList("helicopter")).isEmpty();
|
||||
assertInStdout("Update reserved list for xn--q9jyb4c_common-reserved?");
|
||||
assertInStdout("helicopter: helicopter,FULLY_BLOCKED -> null");
|
||||
assertInStdout("baddies: null -> baddies,FULLY_BLOCKED");
|
||||
assertInStdout("ford: null -> ford,FULLY_BLOCKED # random comment");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,11 +133,13 @@ class UpdateReservedListCommandTest
|
||||
// CreateOrUpdateReservedListCommandTestCases.java
|
||||
UpdateReservedListCommand command = new UpdateReservedListCommand();
|
||||
command.input = Paths.get(reservedTermsPath);
|
||||
command.shouldPublish = false;
|
||||
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)]");
|
||||
assertThat(command.prompt()).contains("shouldPublish: true -> false");
|
||||
assertThat(command.prompt()).contains("helicopter: helicopter,FULLY_BLOCKED -> null");
|
||||
assertThat(command.prompt()).contains("baddies: null -> baddies,FULLY_BLOCKED");
|
||||
assertThat(command.prompt()).contains("ford: null -> ford,FULLY_BLOCKED # random comment");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user