Skip to content

Commit

Permalink
Test locations with trailing whitespace for all filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jul 12, 2023
1 parent 5a6a6f8 commit c66d37d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ final void cleanup()
fileSystemFactory = null;
}

/**
* Tests same things as {@link #testFileWithTrailingWhitespace()} but with setup and assertions using {@link S3Client}.
*/
@Test
public void testFileWithTrailingWhitespace()
public void testFileWithTrailingWhitespaceAgainstNativeClient()
throws IOException
{
try (S3Client s3Client = createS3Client()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.filesystem;

import com.google.common.collect.Ordering;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closer;
import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
Expand Down Expand Up @@ -825,6 +826,57 @@ public void testDirectoryExists()
}
}

@Test
public void testFileWithTrailingWhitespace()
throws IOException
{
try (Closer closer = Closer.create()) {
Location location = createBlob(closer, "dir/whitespace ");

// Verify listing
assertThat(listPath("dir")).isEqualTo(List.of(location));

// Verify reading
TrinoInputFile inputFile = getFileSystem().newInputFile(location);
assertThat(inputFile.exists()).as("exists").isTrue();
try (TrinoInputStream inputStream = inputFile.newStream()) {
byte[] bytes = ByteStreams.toByteArray(inputStream);
assertThat(bytes).isEqualTo(("test blob content for " + location).getBytes(UTF_8));
}

// Verify writing
byte[] newContents = "bar bar baz new content".getBytes(UTF_8);
try (OutputStream outputStream = getFileSystem().newOutputFile(location).createOrOverwrite()) {
outputStream.write(newContents.clone());
}
try (TrinoInputStream inputStream = inputFile.newStream()) {
byte[] bytes = ByteStreams.toByteArray(inputStream);
assertThat(bytes).isEqualTo(newContents);
}

// Verify deleting
getFileSystem().deleteFile(location);
assertThat(inputFile.exists()).as("exists after delete").isFalse();

// Verify renames
if (supportsRenameFile()) {
Location source = createBlob(closer, "dir/another trailing whitespace ");
Location target = getRootLocation().appendPath("dir/after rename still whitespace ");
getFileSystem().renameFile(source, target);
assertThat(getFileSystem().newInputFile(source).exists()).as("source exists after rename").isFalse();
assertThat(getFileSystem().newInputFile(target).exists()).as("target exists after rename").isTrue();

try (TrinoInputStream inputStream = getFileSystem().newInputFile(target).newStream()) {
byte[] bytes = ByteStreams.toByteArray(inputStream);
assertThat(bytes).isEqualTo(("test blob content for " + source).getBytes(UTF_8));
}

getFileSystem().deleteFile(target);
assertThat(getFileSystem().newInputFile(target).exists()).as("target exists after delete").isFalse();
}
}
}

private List<Location> listPath(String path)
throws IOException
{
Expand Down

0 comments on commit c66d37d

Please sign in to comment.