From 8f8ffe70205ea75e024c3ab5cec02840d529fc7c Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Fri, 20 Oct 2023 16:16:05 -0400 Subject: [PATCH] Add a dryrun flag to configure_tld command (#2188) This will be used for presubmit testing. --- .../registry/tools/ConfigureTldCommand.java | 8 ++++++++ .../tools/ConfigureTldCommandTest.java | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/core/src/main/java/google/registry/tools/ConfigureTldCommand.java b/core/src/main/java/google/registry/tools/ConfigureTldCommand.java index 6a6393162..b548743c0 100644 --- a/core/src/main/java/google/registry/tools/ConfigureTldCommand.java +++ b/core/src/main/java/google/registry/tools/ConfigureTldCommand.java @@ -71,6 +71,11 @@ public class ConfigureTldCommand extends MutatingCommand { + " configuration in the database.") boolean breakglass; + @Parameter( + names = {"-d", "--dryrun"}, + description = "Does not execute the entity mutation") + boolean dryrun; + @Inject ObjectMapper mapper; @Inject @@ -126,6 +131,9 @@ public class ConfigureTldCommand extends MutatingCommand { @Override protected boolean dontRunCommand() { + if (dryrun) { + return true; + } if (!newDiff) { if (oldTldInBreakglass && !breakglass) { // Run command to remove breakglass mode diff --git a/core/src/test/java/google/registry/tools/ConfigureTldCommandTest.java b/core/src/test/java/google/registry/tools/ConfigureTldCommandTest.java index 7df2ae8d3..52262eb61 100644 --- a/core/src/test/java/google/registry/tools/ConfigureTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/ConfigureTldCommandTest.java @@ -41,6 +41,7 @@ import com.google.common.io.Files; import com.google.common.testing.TestLogHandler; import google.registry.model.domain.token.AllocationToken; 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.PremiumListDao; import java.io.File; @@ -570,4 +571,23 @@ public class ConfigureTldCommandTest extends CommandTestCase 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)); + } }