This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Cunha
committed
Sep 25, 2017
1 parent
48fd3a6
commit 61c25ae
Showing
4 changed files
with
96 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package data | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type S3Path struct { | ||
bucket string | ||
path string | ||
} | ||
|
||
func (p *S3Path) Basename() string { | ||
components := strings.Split(p.path, "/") | ||
return components[len(components)-1] | ||
} | ||
|
||
func (p *S3Path) Dirname() string { | ||
components := strings.Split(p.path, "/") | ||
if len(components) == 0 { | ||
return "" | ||
} | ||
return strings.Join(components[:len(components)-1], "/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package data | ||
|
||
import "testing" | ||
|
||
func TestBasename(t *testing.T) { | ||
path := S3Path{ | ||
bucket: "foo", | ||
path: "aaa/bbb/ccc", | ||
} | ||
|
||
dirname := path.Basename() | ||
expectation := "ccc" | ||
|
||
if dirname != expectation { | ||
t.Errorf("Basename was incorrect, got: %s, want: %s.", dirname, expectation) | ||
} | ||
} | ||
|
||
func TestBasenameWithEmptyPath(t *testing.T) { | ||
path := S3Path{ | ||
bucket: "foo", | ||
path: "", | ||
} | ||
|
||
dirname := path.Basename() | ||
expectation := "" | ||
|
||
if dirname != expectation { | ||
t.Errorf("Basename was incorrect, got: %s, want: %s.", dirname, expectation) | ||
} | ||
} | ||
|
||
func TestDirname(t *testing.T) { | ||
path := S3Path{ | ||
bucket: "foo", | ||
path: "aaa/bbb/ccc", | ||
} | ||
|
||
dirname := path.Dirname() | ||
expectation := "aaa/bbb" | ||
|
||
if dirname != expectation { | ||
t.Errorf("Dirname was incorrect, got: %s, want: %s.", dirname, expectation) | ||
} | ||
} | ||
|
||
func TestDirnameOnBasicPath(t *testing.T) { | ||
path := S3Path{ | ||
bucket: "foo", | ||
path: "aaa", | ||
} | ||
|
||
dirname := path.Dirname() | ||
expectation := "" | ||
|
||
if dirname != expectation { | ||
t.Errorf("Dirname was incorrect, got: %s, want: %s.", dirname, expectation) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.