Skip to content

Commit

Permalink
Copy zip file to temp folder in tests to avoid creating an unzipped f…
Browse files Browse the repository at this point in the history
…ile not cleaned up by tests
  • Loading branch information
tdrwenski committed May 31, 2024
1 parent 43fd5ef commit 3275086
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

package ucar.nc2.iosp.zarr;

import java.nio.file.*;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import ucar.ma2.Array;
import ucar.ma2.DataType;
import ucar.ma2.InvalidRangeException;
Expand All @@ -28,6 +31,9 @@
*/
public class TestZarrIosp {

@ClassRule
public static TemporaryFolder tempFolder = new TemporaryFolder();

// file names
private static final String ZARR_FILENAME = "zarr_test_data.zarr/";
private static final String ZARR_ZIP_NAME = "zarr_test_data.zip";
Expand All @@ -46,18 +52,23 @@ public class TestZarrIosp {

// Non zarr zipped file
private static final String NON_ZARR_DATA = ZarrTestsCommon.LOCAL_TEST_DATA_PATH + NON_ZARR_FILENAME;
// Copy to temp folder so unzipped file created when opened will get cleaned up after test
private static String TEMP_NON_ZARR_DATA;

// fill values file
private static final String FILL_VALUES_DATA = ZarrTestsCommon.LOCAL_TEST_DATA_PATH + FILL_VALUES_FILENAME;

private static List<String> stores;

@BeforeClass
public static void setUpTests() {
public static void setUpTests() throws IOException {
stores = new ArrayList<>();
stores.add(DIRECTORY_STORE_URI);
stores.add(ZIP_STORE_URI);
stores.add(OBJECT_STORE_ZARR_URI);

TEMP_NON_ZARR_DATA =
Files.copy(Paths.get(NON_ZARR_DATA), Paths.get(tempFolder.getRoot().toString(), NON_ZARR_FILENAME)).toString();
}

@Test
Expand All @@ -72,7 +83,7 @@ public void testIsValidFile() throws IOException {
@Test
public void testNonZarrZipIsNotValid() throws IOException {
ZarrIosp iosp = new ZarrIosp();
assertThat(iosp.isValidFile(NetcdfFiles.getRaf(NON_ZARR_DATA, -1))).isFalse();
assertThat(iosp.isValidFile(NetcdfFiles.getRaf(TEMP_NON_ZARR_DATA, -1))).isFalse();
}

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -254,7 +265,7 @@ private void _testUninitialized(String location) throws IOException, InvalidRang

@Test
public void testReadNonZarrZipFile() throws IOException {
try (NetcdfFile ncfile = NetcdfFiles.open(NON_ZARR_DATA)) {
try (NetcdfFile ncfile = NetcdfFiles.open(TEMP_NON_ZARR_DATA)) {
assertThat(ncfile).isNotNull();
assertThat(ncfile.findDimension("x")).isNotNull();
}
Expand Down

0 comments on commit 3275086

Please sign in to comment.