fixed mock s3 list dirs
This commit is contained in:
parent
a10593a318
commit
2ae14cdfd4
@ -47,14 +47,30 @@ func (m *mockS3) ListBuckets(ctx context.Context) ([]string, error) {
|
||||
func (m *mockS3) ListObjects(ctx context.Context, id types.ID) ([]Object, error) {
|
||||
var results []Object
|
||||
|
||||
dirs := make(map[string]bool)
|
||||
|
||||
depth := len(strings.Split(id.Key, "/"))
|
||||
|
||||
for k, v := range m.objects {
|
||||
if k.Bucket == id.Bucket {
|
||||
if k.Parent().Key == id.Key {
|
||||
results = append(results, *mockObjToObject(v, k))
|
||||
} else if strings.HasPrefix(k.Key, id.Key) {
|
||||
s := strings.Join(strings.Split(k.Key, "/")[:depth], "/") + "/"
|
||||
dirs[s] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range dirs {
|
||||
results = append(results, Object{
|
||||
ID: types.ID{
|
||||
Bucket: id.Bucket,
|
||||
Key: k,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user