Add Plugin Host Set Repo Create, List, Read Operations (#1497)

Add repo for plugin based host sets as well as tests.
This commit is contained in:
Todd Knight authored and GitHub committed 2021-09-09 10:45:41 -07:00
1 parent 7769452f3b
commit 1249f9668f
13 files changed
+819 -43

No files matched your search

+22 -5
View File
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -16,35 +17,51 @@ import (
func TestCatalog(t *testing.T, conn *gorm.DB, pluginId, scopeId string, opt ...Option) *HostCatalog {
t.Helper()
ctx := context.Background()
w := db.New(conn)
cat, err := NewHostCatalog(ctx, pluginId, scopeId, opt...)
require.NoError(t, err)
assert.NotNil(t, cat)
id, err := newHostCatalogId()
plg := host.NewPlugin("", "")
plg.PublicId = pluginId
require.NoError(t, w.LookupByPublicId(ctx, plg))
id, err := newHostCatalogId(plg.GetIdPrefix())
assert.NoError(t, err)
assert.NotEmpty(t, id)
cat.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(ctx, cat))
return cat
}
// TestSet creates count number of plugin host sets in the provided DB
// TestSet creates a plugin host sets in the provided DB
// with the provided catalog id. The catalog must have been created
// previously. The test will fail if any errors are encountered.
func TestSet(t *testing.T, conn *gorm.DB, catalogId string, opt ...Option) *HostSet {
t.Helper()
ctx := context.Background()
w := db.New(conn)
assert := assert.New(t)
set, err := NewHostSet(ctx, catalogId, opt...)
require.NoError(t, err)
assert.NotNil(set)
id, err := newHostSetId()
cg := allocHostCatalog()
cg.PublicId = catalogId
require.NoError(t, w.LookupByPublicId(ctx, cg))
plg := host.NewPlugin("", "")
plg.PublicId = cg.GetPluginId()
require.NoError(t, w.LookupByPublicId(ctx, plg))
id, err := newHostSetId(plg.GetIdPrefix())
assert.NoError(err)
assert.NotEmpty(id)
set.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(ctx, set))
return set
}