mirror of
https://github.com/google/nomulus.git
synced 2025-07-27 13:06:27 +02:00
Fix the output slightly when running nomulus update_premium_list (#2065)
It was previously calling toString() on an Optional<PremiumList> which was unnecessarily verbose. The existing premium list is required to be present anyway.
This commit is contained in:
parent
8e31951241
commit
a5207797f4
2 changed files with 16 additions and 21 deletions
|
@ -24,7 +24,6 @@ import google.registry.model.tld.label.PremiumList;
|
||||||
import google.registry.model.tld.label.PremiumListDao;
|
import google.registry.model.tld.label.PremiumListDao;
|
||||||
import google.registry.model.tld.label.PremiumListUtils;
|
import google.registry.model.tld.label.PremiumListUtils;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/** Command to safely update {@link PremiumList} in Database for a given TLD. */
|
/** Command to safely update {@link PremiumList} in Database for a given TLD. */
|
||||||
@Parameters(separators = " =", commandDescription = "Update a PremiumList in Database.")
|
@Parameters(separators = " =", commandDescription = "Update a PremiumList in Database.")
|
||||||
|
@ -33,16 +32,19 @@ class UpdatePremiumListCommand extends CreateOrUpdatePremiumListCommand {
|
||||||
@Override
|
@Override
|
||||||
protected String prompt() throws Exception {
|
protected String prompt() throws Exception {
|
||||||
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
|
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
|
||||||
Optional<PremiumList> list = PremiumListDao.getLatestRevision(name);
|
PremiumList existingList =
|
||||||
checkArgument(
|
PremiumListDao.getLatestRevision(name)
|
||||||
list.isPresent(),
|
.orElseThrow(
|
||||||
String.format("Could not update premium list %s because it doesn't exist.", name));
|
() ->
|
||||||
|
new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Could not update premium list %s because it doesn't exist", name)));
|
||||||
inputData = Files.readAllLines(inputFile, UTF_8);
|
inputData = Files.readAllLines(inputFile, UTF_8);
|
||||||
checkArgument(!inputData.isEmpty(), "New premium list data cannot be empty");
|
checkArgument(!inputData.isEmpty(), "New premium list data cannot be empty");
|
||||||
currency = list.get().getCurrency();
|
currency = existingList.getCurrency();
|
||||||
PremiumList updatedPremiumList = PremiumListUtils.parseToPremiumList(name, currency, inputData);
|
PremiumList updatedPremiumList = PremiumListUtils.parseToPremiumList(name, currency, inputData);
|
||||||
return String.format(
|
return String.format(
|
||||||
"Update premium list for %s?\n Old List: %s\n New List: %s",
|
"Update premium list for %s?\n Old List: %s\n New List: %s",
|
||||||
name, list, updatedPremiumList);
|
name, existingList, updatedPremiumList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,15 +134,13 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void commandPrompt_failureNoPreviousVersion() {
|
void commandPrompt_failureNoPreviousVersion() {
|
||||||
String fileName = "random";
|
registry = createTld("random", null, null);
|
||||||
registry = createTld(fileName, null, null);
|
|
||||||
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
||||||
command.name = fileName;
|
command.name = "random";
|
||||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
.hasMessageThat()
|
.hasMessageThat()
|
||||||
.isEqualTo(
|
.isEqualTo("Could not update premium list random because it doesn't exist");
|
||||||
String.format("Could not update premium list %s because it doesn't exist.", fileName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -153,27 +151,22 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void commandPrompt_failureTldFromNameDoesNotExist() {
|
void commandPrompt_failureTldFromNameDoesNotExist() {
|
||||||
String fileName = "random";
|
|
||||||
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
||||||
command.name = fileName;
|
command.name = "random2";
|
||||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
.hasMessageThat()
|
.hasMessageThat()
|
||||||
.isEqualTo(
|
.isEqualTo("Could not update premium list random2 because it doesn't exist");
|
||||||
String.format("Could not update premium list %s because it doesn't exist.", fileName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void commandPrompt_failureTldFromInputFileDoesNotExist() {
|
void commandPrompt_failureTldFromInputFileDoesNotExist() {
|
||||||
String fileName = "random";
|
|
||||||
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
|
||||||
// using tld extracted from file name but this tld is not part of the registry
|
// using tld extracted from file name but this tld is not part of the registry
|
||||||
command.inputFile =
|
command.inputFile = Paths.get(tmpDir.resolve("random3.txt").toFile().getPath());
|
||||||
Paths.get(tmpDir.resolve(String.format("%s.txt", fileName)).toFile().getPath());
|
|
||||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
.hasMessageThat()
|
.hasMessageThat()
|
||||||
.isEqualTo(
|
.isEqualTo("Could not update premium list random3 because it doesn't exist");
|
||||||
String.format("Could not update premium list %s because it doesn't exist.", fileName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue