From 916d9ef607ff455a50121fcc439d6be489d3d0cc Mon Sep 17 00:00:00 2001 From: courtneyeh Date: Fri, 12 Apr 2024 08:00:49 +1000 Subject: [PATCH] Add test for IO exception --- .../statetransition/util/DebugDataDumperTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java index 6e4b4094800..a2e8bfdc6ce 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.fail; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; @@ -122,13 +123,24 @@ void saveInvalidBlockToFile_shouldNotSaveToFileWhenDisabled(@TempDir Path tempDi } @Test - void saveBytesToFile_shouldNotThrowExceptionWhenUnableToSave(@TempDir Path tempDir) { + void saveBytesToFile_shouldNotThrowExceptionWhenNoDirectory(@TempDir Path tempDir) { final DebugDataDumper manager = new DebugDataDumper(tempDir, true); assertDoesNotThrow( () -> manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY)); } + @Test + void saveBytesToFile_shouldNotEscalateWhenIOException(@TempDir Path tempDir) { + final DebugDataDumper manager = new DebugDataDumper(tempDir, true); + final File invalidPath = tempDir.resolve("invalid").toFile(); + assertThat(invalidPath.mkdirs()).isTrue(); + assertThat(invalidPath.setWritable(false)).isTrue(); + assertDoesNotThrow( + () -> + manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY)); + } + private void checkBytesSavedToFile(final Path path, final Bytes expectedBytes) { try { final Bytes bytes = Bytes.wrap(Files.readAllBytes(path));