Add stageEntityChange() method to display difference when creating a reserved list (#1149)

* Add stageEntityChange() method to display difference before execution when creating a reserved list
This commit is contained in:
Rachel Guan
2021-05-12 17:32:57 -04:00
committed by GitHub
parent 484e30cd80
commit 85bac9834f
2 changed files with 33 additions and 0 deletions
@@ -23,8 +23,11 @@ import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.io.Files;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -185,4 +188,26 @@ class CreateReservedListCommandTest
runCommandForced("--name=" + name, "--override", "--input=" + reservedTermsPath);
assertThat(ReservedList.get(name)).isPresent();
}
@Test
void testStageEntityChange_succeeds() throws Exception {
CreateReservedListCommand command = new CreateReservedListCommand();
// file content is populated in @BeforeEach of CreateOrUpdateReservedListCommandTestCase.java
command.input = Paths.get(reservedTermsPath);
command.init();
assertThat(command.prompt())
.contains(
"reservedListMap={baddies=baddies,FULLY_BLOCKED, "
+ "ford=ford,FULLY_BLOCKED # random comment}");
}
@Test
void testStageEntityChange_succeedsWithEmptyFile() throws Exception {
Path tmpPath = tmpDir.resolve("xn--q9jyb4c_common-tmp.txt");
Files.write(new byte[0], tmpPath.toFile());
CreateReservedListCommand command = new CreateReservedListCommand();
command.input = tmpPath;
command.init();
assertThat(command.prompt()).contains("reservedListMap={}");
}
}