Add support for recursive listing (#885)
This commit is contained in:
1 parent
1f9fcad1cd
commit
6cd97a4a6e
77 files changed
+2244
-1448
No files matched your search
@@ -200,10 +200,10 @@ func (r *Repository) LookupCatalog(ctx context.Context, id string, opt ...Option
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// ListCatalogs returns a slice of HostCatalogs for the scopeId. WithLimit is the only option supported.
|
||||
func (r *Repository) ListCatalogs(ctx context.Context, scopeId string, opt ...Option) ([]*HostCatalog, error) {
|
||||
// ListCatalogs returns a slice of HostCatalogs for the scope IDs. WithLimit is the only option supported.
|
||||
func (r *Repository) ListCatalogs(ctx context.Context, scopeIds []string, opt ...Option) ([]*HostCatalog, error) {
|
||||
const op = "static.(Repository).ListCatalogs"
|
||||
if scopeId == "" {
|
||||
if len(scopeIds) == 0 {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no scope id")
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
@@ -213,7 +213,7 @@ func (r *Repository) ListCatalogs(ctx context.Context, scopeId string, opt ...Op
|
||||
limit = opts.withLimit
|
||||
}
|
||||
var hostCatalogs []*HostCatalog
|
||||
err := r.reader.SearchWhere(ctx, &hostCatalogs, "scope_id = ?", []interface{}{scopeId}, db.WithLimit(limit))
|
||||
err := r.reader.SearchWhere(ctx, &hostCatalogs, "scope_id in (?)", []interface{}{scopeIds}, db.WithLimit(limit))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, op)
|
||||
}
|
||||
|
||||
@@ -680,3 +680,30 @@ func TestRepository_DeleteCatalog(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepository_ListCatalogs_Multiple_Scopes(t *testing.T) {
|
||||
t.Parallel()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrapper := db.TestWrapper(t)
|
||||
rw := db.New(conn)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
repo, err := NewRepository(rw, rw, kms)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, repo)
|
||||
|
||||
const numPerScope = 10
|
||||
var projs []string
|
||||
var total int
|
||||
for i := 0; i < numPerScope; i++ {
|
||||
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
||||
projs = append(projs, prj.GetPublicId())
|
||||
for j := 0; j < numPerScope; j++ {
|
||||
testCatalog(t, conn, prj.PublicId)
|
||||
total++
|
||||
}
|
||||
}
|
||||
|
||||
got, err := repo.ListCatalogs(context.Background(), projs)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, total, len(got))
|
||||
}
|
||||
Reference in new issue
Block a user