Skip to content

Commit

Permalink
fix: add storage ls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Oct 18, 2023
1 parent 925cc1a commit c62e744
Show file tree
Hide file tree
Showing 2 changed files with 414 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/storage/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ func Run(ctx context.Context, objectPath string, recursive bool, fsys afero.Fs)
return nil
}

var errInvalidURL = errors.New("URL must match pattern ss:///bucket/prefix")

func ParseStorageURL(objectPath string) (string, error) {
parsed, err := url.Parse(objectPath)
if err != nil {
return "", err
}
if strings.ToLower(parsed.Scheme) != STORAGE_SCHEME || len(parsed.Path) == 0 || len(parsed.Host) > 0 {
return "", errors.New("URL must match pattern ss:///bucket/prefix")
return "", errInvalidURL
}
return parsed.Path, nil
}
Expand Down Expand Up @@ -108,11 +110,15 @@ func SplitBucketPrefix(objectPath string) (string, string) {
if objectPath == "" || objectPath == "/" {
return "", ""
}
sep := strings.IndexByte(objectPath[1:], '/')
start := 0
if objectPath[0] == '/' {
start = 1
}
sep := strings.IndexByte(objectPath[start:], '/')
if sep < 0 {
return objectPath[1:], ""
return objectPath[start:], ""
}
return objectPath[1 : sep+1], objectPath[sep+2:]
return objectPath[start : sep+start], objectPath[sep+start+1:]
}

// Expects remotePath to be terminated by "/"
Expand Down
Loading

0 comments on commit c62e744

Please sign in to comment.