Commit cde56bf7 authored by ale's avatar ale

Add SearchResource to the fake backend used in tests

parent 7879718b
Pipeline #2181 passed with stages
in 1 minute and 55 seconds
......@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"path/filepath"
"strings"
"testing"
......@@ -81,6 +82,18 @@ func (b *fakeBackend) GetResource(_ context.Context, resourceID ResourceID) (*Ra
return &RawResource{Resource: *r, Owner: owner}, nil
}
func (b *fakeBackend) SearchResource(_ context.Context, pattern string) ([]*RawResource, error) {
var out []*RawResource
for id, r := range b.resources {
owner := strings.Split(id, "/")[0]
// Emulate LDAP wildcard syntax.
if ok, _ := filepath.Match(pattern, r.Name); ok {
out = append(out, &RawResource{Resource: *r, Owner: owner})
}
}
return out, nil
}
func (b *fakeBackend) UpdateResource(_ context.Context, r *Resource) error {
b.resources[r.ID.String()] = r
return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment