Add a dryrun flag to configure_tld command (#2188)

This will be used for presubmit testing.
This commit is contained in:
sarahcaseybot
2023-10-20 16:16:05 -04:00
committed by GitHub
parent 16e5018489
commit 8f8ffe7020
2 changed files with 28 additions and 0 deletions
@@ -71,6 +71,11 @@ public class ConfigureTldCommand extends MutatingCommand {
+ " configuration in the database.") + " configuration in the database.")
boolean breakglass; boolean breakglass;
@Parameter(
names = {"-d", "--dryrun"},
description = "Does not execute the entity mutation")
boolean dryrun;
@Inject ObjectMapper mapper; @Inject ObjectMapper mapper;
@Inject @Inject
@@ -126,6 +131,9 @@ public class ConfigureTldCommand extends MutatingCommand {
@Override @Override
protected boolean dontRunCommand() { protected boolean dontRunCommand() {
if (dryrun) {
return true;
}
if (!newDiff) { if (!newDiff) {
if (oldTldInBreakglass && !breakglass) { if (oldTldInBreakglass && !breakglass) {
// Run command to remove breakglass mode // Run command to remove breakglass mode
@@ -41,6 +41,7 @@ import com.google.common.io.Files;
import com.google.common.testing.TestLogHandler; import com.google.common.testing.TestLogHandler;
import google.registry.model.domain.token.AllocationToken; import google.registry.model.domain.token.AllocationToken;
import google.registry.model.tld.Tld; import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldNotFoundException;
import google.registry.model.tld.label.PremiumList; import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.PremiumListDao; import google.registry.model.tld.label.PremiumListDao;
import java.io.File; import java.io.File;
@@ -570,4 +571,23 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
"Changes can not be applied since TLD is in breakglass mode but the breakglass flag" "Changes can not be applied since TLD is in breakglass mode but the breakglass flag"
+ " was not used"); + " was not used");
} }
@Test
void testSuccess_dryRunOnCreate_noChanges() throws Exception {
File tldFile = tmpDir.resolve("tld.yaml").toFile();
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "tld.yaml"));
runCommandForced("--input=" + tldFile, "--dryrun");
assertThrows(TldNotFoundException.class, () -> Tld.get("tld"));
}
@Test
void testSuccess_dryRunOnUpdate_noChanges() throws Exception {
Tld tld = createTld("tld");
assertThat(tld.getCreateBillingCost()).isEqualTo(Money.of(USD, 13));
File tldFile = tmpDir.resolve("tld.yaml").toFile();
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "tld.yaml"));
runCommandForced("--input=" + tldFile, "-d");
Tld notUpdatedTld = Tld.get("tld");
assertThat(notUpdatedTld.getCreateBillingCost()).isEqualTo(Money.of(USD, 13));
}
} }