Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ennoruijters authored and carlspring committed Jun 7, 2023
1 parent b81e2eb commit 084310d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ void getParent()
assertNull(forPath("/bucket").getParent());
}

@Test
public void normalize()
{
assertEquals(forPath("/bucket"), forPath("/bucket").normalize());
assertEquals(forPath("/bucket/"), forPath("/bucket/").normalize());
assertEquals(forPath("/bucket/"), forPath("/bucket/.").normalize());

// We can't normalize to outside of the bucket
assertEquals(forPath("/bucket/"), forPath("/bucket/..").normalize());
assertEquals(forPath("/bucket/path"), forPath("/bucket/../path").normalize());

// Various different spellings of the same path
assertEquals(forPath("/bucket/path/to"), forPath("/bucket/path/to").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/path/to/").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/path/to/file/../").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/path/to/./").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/./path/to/").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/foo/./../bar/../path/to/").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/path/to/foo/bar/../../").normalize());
assertEquals(forPath("/bucket/path/to/"), forPath("/bucket/././././././foo/./././../././bar/./././../path/./to/././").normalize());

S3Path path = forPath("../bucket/path/to");
assertTrue(path == path.normalize());
}

@Test
void nameCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void startsWithNotNormalize()
void startsWithNormalize()
{
// in this implementation not exists .. or . special paths
assertFalse(getPath("/bucket/file1/file2").startsWith(getPath("/bucket/file1/../").normalize()));
assertTrue(getPath("/bucket/file1/file2").startsWith(getPath("/bucket/file1/../").normalize()));
}

@Test
Expand Down

0 comments on commit 084310d

Please sign in to comment.