Add --set_current_tld_state to UpdateTldCommand

This feature would have been useful earlier when I was changing the TLD state on a sandbox TLD on-the-fly for testing purposes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128088578
This commit is contained in:
ctingue 2016-02-07 12:03:01 -05:00 committed by Ben McIlwain
parent e82a40a2fb
commit a3cade3e20
8 changed files with 147 additions and 7 deletions

View file

@ -94,6 +94,17 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
assertThat(registry.getTldState(END_OF_TIME)).isEqualTo(TldState.GENERAL_AVAILABILITY);
}
@Test
public void testSuccess_setTldState() throws Exception {
Registry registry = persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, TldState.PREDELEGATION))
.build());
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
registry = Registry.get("xn--q9jyb4c");
assertThat(registry.getTldState(now.plusDays(1))).isEqualTo(TldState.SUNRISE);
}
@Test
public void testSuccess_renewBillingCostTransitions() throws Exception {
DateTime later = now.plusMonths(1);
@ -457,6 +468,65 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
"xn--q9jyb4c");
}
@Test
public void testFailure_bothTldStateFlags() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"Don't pass both --set_current_tld_state and --tld_state_transitions");
runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plusDays(1)),
"--set_current_tld_state=GENERAL_AVAILABILITY",
"xn--q9jyb4c");
}
@Test
public void testFailure_setCurrentTldState_outOfOrder() throws Exception {
thrown.expect(
IllegalArgumentException.class, "The TLD states are chronologically out of order");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.of(
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
}
@Test
public void testFailure_setCurrentTldState_laterTransitionScheduled() throws Exception {
thrown.expect(
IllegalArgumentException.class,
" when there is a later transition already scheduled");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.of(
START_OF_TIME, TldState.PREDELEGATION,
now.plusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
}
@Test
public void testFailure_setCurrentTldState_inProduction() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"--set_current_tld_state is not safe to use in production.");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.of(
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
runCommandInEnvironment(
RegistryToolEnvironment.PRODUCTION,
"--set_current_tld_state=SUNRISE",
"xn--q9jyb4c",
"--force");
}
@Test
public void testFailure_invalidRenewBillingCost() throws Exception {
thrown.expect(ParameterException.class);