refact(plugin): Move host loopback plugin into internal/plugin/loopback

This commit is contained in:
Louis Ruch authored and Timothy Messier committed 2023-05-31 12:18:12 +00:00
1 parent 4c801cca18
commit 351444f1bd
28 files changed
+3435 -177

No files matched your search

-59
View File
@@ -1,59 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package plugin
import (
"context"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"google.golang.org/grpc"
)
var _ plgpb.HostPluginServiceClient = (*WrappingPluginClient)(nil)
// WrappingPluginClient provides a wrapper around a Server implementation that
// can be used when loading a plugin in-memory
type WrappingPluginClient struct {
Server plgpb.HostPluginServiceServer
}
func NewWrappingPluginClient(s plgpb.HostPluginServiceServer) *WrappingPluginClient {
return &WrappingPluginClient{Server: s}
}
func (tpc *WrappingPluginClient) NormalizeCatalogData(ctx context.Context, req *plgpb.NormalizeCatalogDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeCatalogDataResponse, error) {
return tpc.Server.NormalizeCatalogData(ctx, req)
}
func (tpc *WrappingPluginClient) OnCreateCatalog(ctx context.Context, req *plgpb.OnCreateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnCreateCatalogResponse, error) {
return tpc.Server.OnCreateCatalog(ctx, req)
}
func (tpc *WrappingPluginClient) OnUpdateCatalog(ctx context.Context, req *plgpb.OnUpdateCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateCatalogResponse, error) {
return tpc.Server.OnUpdateCatalog(ctx, req)
}
func (tpc *WrappingPluginClient) OnDeleteCatalog(ctx context.Context, req *plgpb.OnDeleteCatalogRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteCatalogResponse, error) {
return tpc.Server.OnDeleteCatalog(ctx, req)
}
func (tpc *WrappingPluginClient) NormalizeSetData(ctx context.Context, req *plgpb.NormalizeSetDataRequest, opts ...grpc.CallOption) (*plgpb.NormalizeSetDataResponse, error) {
return tpc.Server.NormalizeSetData(ctx, req)
}
func (tpc *WrappingPluginClient) OnCreateSet(ctx context.Context, req *plgpb.OnCreateSetRequest, opts ...grpc.CallOption) (*plgpb.OnCreateSetResponse, error) {
return tpc.Server.OnCreateSet(ctx, req)
}
func (tpc *WrappingPluginClient) OnUpdateSet(ctx context.Context, req *plgpb.OnUpdateSetRequest, opts ...grpc.CallOption) (*plgpb.OnUpdateSetResponse, error) {
return tpc.Server.OnUpdateSet(ctx, req)
}
func (tpc *WrappingPluginClient) OnDeleteSet(ctx context.Context, req *plgpb.OnDeleteSetRequest, opts ...grpc.CallOption) (*plgpb.OnDeleteSetResponse, error) {
return tpc.Server.OnDeleteSet(ctx, req)
}
func (tpc *WrappingPluginClient) ListHosts(ctx context.Context, req *plgpb.ListHostsRequest, opts ...grpc.CallOption) (*plgpb.ListHostsResponse, error) {
return tpc.Server.ListHosts(ctx, req)
}
+2 -1
View File
@@ -15,6 +15,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
hostplg "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/stretchr/testify/assert"
@@ -35,7 +36,7 @@ func TestHostSetMember_InsertDelete(t *testing.T) {
plg := hostplg.TestPlugin(t, conn, "create")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}),
}
repo, err := NewRepository(rw, rw, kms, sched, plgm)
@@ -13,6 +13,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/stretchr/testify/assert"
@@ -108,7 +109,7 @@ func TestPluginSet_ImmutableFields(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
new := TestSet(t, conn, kmsCache, sched, cat, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
})
tests := []struct {
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
hostplg "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/stretchr/testify/assert"
@@ -105,10 +106,10 @@ func TestOrphanedHostCleanupJob_Run(t *testing.T) {
kmsCache := kms.TestKms(t, conn, wrapper)
sched := scheduler.TestScheduler(t, conn, wrapper)
plgServer := &TestPluginServer{}
plgServer := &loopback.TestPluginServer{}
plg := hostplg.TestPlugin(t, conn, "run")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(plgServer),
plg.GetPublicId(): loopback.NewWrappingPluginClient(plgServer),
}
r, err := newOrphanedHostCleanupJob(ctx, rw, rw, kmsCache)
+5 -4
View File
@@ -15,6 +15,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
hostplg "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
assertpkg "github.com/stretchr/testify/assert"
@@ -31,7 +32,7 @@ func TestNewSetSyncJob(t *testing.T) {
plg := hostplg.TestPlugin(t, conn, "lookup")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
type args struct {
@@ -142,10 +143,10 @@ func TestSetSyncJob_Run(t *testing.T) {
kmsCache := kms.TestKms(t, conn, wrapper)
sched := scheduler.TestScheduler(t, conn, wrapper)
plgServer := &TestPluginServer{}
plgServer := &loopback.TestPluginServer{}
plg := hostplg.TestPlugin(t, conn, "run")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(plgServer),
plg.GetPublicId(): loopback.NewWrappingPluginClient(plgServer),
}
r, err := newSetSyncJob(ctx, rw, rw, kmsCache, plgm)
@@ -413,7 +414,7 @@ func TestSetSyncJob_NextRunIn(t *testing.T) {
_, prj := iam.TestScopes(t, iamRepo)
plg := hostplg.TestPlugin(t, conn, "lookup")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
hostSet := TestSet(t, conn, kmsCache, sched, catalog, plgm)
-193
View File
@@ -1,193 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package plugin
import (
"context"
"fmt"
"github.com/hashicorp/boundary/internal/errors"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/mitchellh/mapstructure"
)
const loopbackPluginHostInfoAttrField = "host_info"
var _ plgpb.HostPluginServiceServer = (*loopbackPlugin)(nil)
// loopbackPlugin provides a host plugin with functionality useful for certain
// kinds of testing. It is not (currently) thread-safe.
//
// Over time, if useful, it can be enhanced to do things like handle multiple
// hosts per set.
type loopbackPlugin struct {
*TestPluginServer
hostMap map[string][]*loopbackPluginHostInfo
}
type loopbackPluginHostInfo struct {
ExternalId string `mapstructure:"external_id"`
IpAddresses []string `mapstructure:"ip_addresses"`
DnsNames []string `mapstructure:"dns_names"`
}
// NewLoopbackPlugin returns a new loopback plugin
func NewLoopbackPlugin() plgpb.HostPluginServiceServer {
ret := &loopbackPlugin{
TestPluginServer: new(TestPluginServer),
hostMap: make(map[string][]*loopbackPluginHostInfo),
}
ret.OnCreateCatalogFn = ret.onCreateCatalog
ret.OnUpdateCatalogFn = ret.onUpdateCatalog
ret.OnCreateSetFn = ret.onCreateSet
ret.OnUpdateSetFn = ret.onUpdateSet
ret.OnDeleteSetFn = ret.onDeleteSet
ret.ListHostsFn = ret.listHosts
return ret
}
func (l *loopbackPlugin) onCreateCatalog(ctx context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
const op = "plugin.(loopbackPlugin).onCreateCatalog"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
if cat := req.GetCatalog(); cat != nil {
if secrets := cat.GetSecrets(); secrets != nil {
return &plgpb.OnCreateCatalogResponse{
Persisted: &plgpb.HostCatalogPersisted{
Secrets: secrets,
},
}, nil
}
}
return &plgpb.OnCreateCatalogResponse{}, nil
}
func (l *loopbackPlugin) onUpdateCatalog(ctx context.Context, req *plgpb.OnUpdateCatalogRequest) (*plgpb.OnUpdateCatalogResponse, error) {
const op = "plugin.(loopbackPlugin).onUpdateCatalog"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
if cat := req.GetNewCatalog(); cat != nil {
if secrets := cat.GetSecrets(); secrets != nil {
return &plgpb.OnUpdateCatalogResponse{
Persisted: &plgpb.HostCatalogPersisted{
Secrets: secrets,
},
}, nil
}
}
return &plgpb.OnUpdateCatalogResponse{}, nil
}
func (l *loopbackPlugin) onCreateSet(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
const op = "plugin.(loopbackPlugin).onCreateSet"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
set := req.GetSet()
if set == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "set is nil")
}
if attrs := set.GetAttributes(); attrs != nil {
attrsMap := attrs.AsMap()
if field := attrsMap[loopbackPluginHostInfoAttrField]; field != nil {
switch t := field.(type) {
case []any:
for _, h := range t {
hostInfo := new(loopbackPluginHostInfo)
if err := mapstructure.Decode(h, hostInfo); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
l.hostMap[set.GetId()] = append(l.hostMap[set.GetId()], hostInfo)
}
case map[string]any:
hostInfo := new(loopbackPluginHostInfo)
if err := mapstructure.Decode(t, hostInfo); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
l.hostMap[set.GetId()] = append(l.hostMap[set.GetId()], hostInfo)
default:
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("unknown host info type %T", t))
}
}
}
return &plgpb.OnCreateSetResponse{}, nil
}
func (l *loopbackPlugin) onUpdateSet(ctx context.Context, req *plgpb.OnUpdateSetRequest) (*plgpb.OnUpdateSetResponse, error) {
const op = "plugin.(loopbackPlugin).onCreateSet"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
set := req.GetNewSet()
if set == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "set is nil")
}
var hosts []*loopbackPluginHostInfo
if attrs := set.GetAttributes(); attrs != nil {
attrsMap := attrs.AsMap()
if field := attrsMap[loopbackPluginHostInfoAttrField]; field != nil {
switch t := field.(type) {
case []any:
for _, h := range t {
hostInfo := new(loopbackPluginHostInfo)
if err := mapstructure.Decode(h, hostInfo); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
hosts = append(hosts, hostInfo)
}
case map[string]any:
hostInfo := new(loopbackPluginHostInfo)
if err := mapstructure.Decode(t, hostInfo); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
hosts = append(hosts, hostInfo)
default:
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("unknown host info type %T", t))
}
}
}
if hosts != nil {
l.hostMap[set.GetId()] = hosts
}
return &plgpb.OnUpdateSetResponse{}, nil
}
func (l *loopbackPlugin) onDeleteSet(ctx context.Context, req *plgpb.OnDeleteSetRequest) (*plgpb.OnDeleteSetResponse, error) {
const op = "plugin.(loopbackPlugin).onDeleteSet"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
set := req.GetSet()
if set == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "set is nil")
}
delete(l.hostMap, set.GetId())
return nil, nil
}
func (l *loopbackPlugin) listHosts(ctx context.Context, req *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error) {
const op = "plugin.(loopbackPlugin).listHosts"
if req == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "req is nil")
}
resp := new(plgpb.ListHostsResponse)
for _, set := range req.GetSets() {
hostInfos := l.hostMap[set.GetId()]
if len(hostInfos) == 0 {
continue
}
for _, host := range hostInfos {
resp.Hosts = append(resp.Hosts, &plgpb.ListHostsResponseHost{
SetIds: []string{set.GetId()},
ExternalId: host.ExternalId,
IpAddresses: host.IpAddresses,
DnsNames: host.DnsNames,
})
}
}
return resp, nil
}
-373
View File
@@ -1,373 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package plugin
import (
"context"
"testing"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostcatalogs"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
ta "github.com/stretchr/testify/assert"
tr "github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"
)
// TestLoopbackPlugin is a quick test of basic functionality.
func TestLoopbackPlugin(t *testing.T) {
require, assert := tr.New(t), ta.New(t)
ctx := context.Background()
plg := NewLoopbackPlugin()
secretsMap := map[string]any{
"key1": "key2",
"baz": true,
}
secrets, err := structpb.NewStruct(secretsMap)
require.NoError(err)
// First, test that if we give it secrets, those secrets come back as
// persisted data
catResp, err := plg.OnCreateCatalog(ctx, &plgpb.OnCreateCatalogRequest{
Catalog: &hostcatalogs.HostCatalog{
Secrets: secrets,
},
})
require.NoError(err)
require.NotNil(catResp)
require.NotNil(catResp.GetPersisted())
require.NotNil(catResp.GetPersisted().GetSecrets())
assert.EqualValues(secretsMap, catResp.GetPersisted().GetSecrets().AsMap())
newSecretsMap := map[string]any{
"key1": "key2",
"baz": true,
}
newSecrets, err := structpb.NewStruct(newSecretsMap)
require.NoError(err)
// First, test that if we give it secrets, those secrets come back as
// persisted data
upResp, err := plg.OnUpdateCatalog(ctx, &plgpb.OnUpdateCatalogRequest{
CurrentCatalog: &hostcatalogs.HostCatalog{},
NewCatalog: &hostcatalogs.HostCatalog{
Secrets: newSecrets,
},
Persisted: &plgpb.HostCatalogPersisted{
Secrets: secrets,
},
})
require.NoError(err)
require.NotNil(upResp)
require.NotNil(upResp.GetPersisted())
require.NotNil(upResp.GetPersisted().GetSecrets())
assert.EqualValues(newSecretsMap, upResp.GetPersisted().GetSecrets().AsMap())
// Add data to some sets
hostInfo1 := map[string]any{
loopbackPluginHostInfoAttrField: map[string]any{
"set_ids": []any{"set1"},
"external_id": "host1",
"ip_addresses": []any{"1.2.3.4", "2.3.4.5"},
"dns_names": []any{"foo.com"},
},
}
attrs, err := structpb.NewStruct(hostInfo1)
require.NoError(err)
_, err = plg.OnCreateSet(ctx, &plgpb.OnCreateSetRequest{
Set: &hostsets.HostSet{
Id: "set1",
Attrs: &hostsets.HostSet_Attributes{
Attributes: attrs,
},
},
})
require.NoError(err)
hostInfo2 := map[string]any{
loopbackPluginHostInfoAttrField: map[string]any{
"set_ids": []any{"set2"},
"external_id": "host2",
"ip_addresses": []any{"5.6.7.8", "6.7.8.9"},
"dns_names": []any{"bar.com"},
},
}
attrs, err = structpb.NewStruct(hostInfo2)
require.NoError(err)
_, err = plg.OnCreateSet(ctx, &plgpb.OnCreateSetRequest{
Set: &hostsets.HostSet{
Id: "set2",
Attrs: &hostsets.HostSet_Attributes{
Attributes: attrs,
},
},
})
require.NoError(err)
// Define test struct and validation function
type testInfo struct {
name string
sets []string
found []map[string]any
}
validateSets := func(t *testing.T, tt testInfo) {
require, assert := tr.New(t), ta.New(t)
var hostSets []*hostsets.HostSet
for _, set := range tt.sets {
hostSets = append(hostSets, &hostsets.HostSet{Id: set})
}
resp, err := plg.ListHosts(ctx, &plgpb.ListHostsRequest{
Sets: hostSets,
})
require.NoError(err)
if len(tt.found) == 0 {
assert.Len(resp.GetHosts(), 0)
return
}
require.Greater(len(resp.GetHosts()), 0)
var found []map[string]any
for _, host := range resp.GetHosts() {
hostMap := map[string]any{
"external_id": host.GetExternalId(),
}
var sets []any
for _, set := range host.SetIds {
sets = append(sets, set)
}
var ips []any
for _, ip := range host.GetIpAddresses() {
ips = append(ips, ip)
}
var names []any
for _, name := range host.GetDnsNames() {
names = append(names, name)
}
if len(sets) > 0 {
hostMap["set_ids"] = sets
}
if len(ips) > 0 {
hostMap["ip_addresses"] = ips
}
if len(names) > 0 {
hostMap["dns_names"] = names
}
found = append(found, hostMap)
}
assert.ElementsMatch(tt.found, found)
}
// First set of tests: check that we can look up sets individually and
// together
setTests := []testInfo{
{
name: "set 1",
sets: []string{"set1"},
found: []map[string]any{
hostInfo1[loopbackPluginHostInfoAttrField].(map[string]any),
},
},
{
name: "set 2",
sets: []string{"set2"},
found: []map[string]any{
hostInfo2[loopbackPluginHostInfoAttrField].(map[string]any),
},
},
{
name: "sets 1 and 2",
sets: []string{"set1", "set2"},
found: []map[string]any{
hostInfo1[loopbackPluginHostInfoAttrField].(map[string]any),
hostInfo2[loopbackPluginHostInfoAttrField].(map[string]any),
},
},
}
for _, tt := range setTests {
t.Run(tt.name, func(t *testing.T) {
validateSets(t, tt)
})
}
// Remove a set
_, err = plg.OnDeleteSet(ctx, &plgpb.OnDeleteSetRequest{
Set: &hostsets.HostSet{
Id: "set1",
},
})
require.NoError(err)
// Run tests again, making sure we no longer find that host either
// individually or together
setTests = []testInfo{
{
name: "set 1 deleted",
sets: []string{"set1"},
found: []map[string]any{},
},
{
name: "set 2 not deleted",
sets: []string{"set2"},
found: []map[string]any{
hostInfo2[loopbackPluginHostInfoAttrField].(map[string]any),
},
},
{
name: "sets 1 and 2 set 1 deleted",
sets: []string{"set1", "set2"},
found: []map[string]any{
hostInfo2[loopbackPluginHostInfoAttrField].(map[string]any),
},
},
}
for _, tt := range setTests {
t.Run(tt.name, func(t *testing.T) {
validateSets(t, tt)
})
}
}
func TestLoopbackPluginArrays(t *testing.T) {
require := tr.New(t)
ctx := context.Background()
plg := NewLoopbackPlugin()
// Add data to some sets
hostInfo1 := map[string]any{
loopbackPluginHostInfoAttrField: []any{
map[string]any{
"set_ids": []any{"set1"},
"external_id": "host1a",
"ip_addresses": []any{"1.2.3.4", "2.3.4.5"},
"dns_names": []any{"foo.com"},
},
map[string]any{
"set_ids": []any{"set1"},
"external_id": "host1b",
"ip_addresses": []any{"3.4.5.6", "4.5.6.7"},
"dns_names": []any{"bar.com"},
},
},
}
attrs, err := structpb.NewStruct(hostInfo1)
require.NoError(err)
_, err = plg.OnCreateSet(ctx, &plgpb.OnCreateSetRequest{
Set: &hostsets.HostSet{
Id: "set1",
Attrs: &hostsets.HostSet_Attributes{
Attributes: attrs,
},
},
})
require.NoError(err)
hostInfo2 := map[string]any{
loopbackPluginHostInfoAttrField: []any{
map[string]any{
"set_ids": []any{"set2"},
"external_id": "host2a",
"ip_addresses": []any{"10.20.30.40", "20.30.40.50"},
"dns_names": []any{"foz.com"},
},
map[string]any{
"set_ids": []any{"set2"},
"external_id": "host2b",
"ip_addresses": []any{"30.40.50.60", "40.50.60.70"},
"dns_names": []any{"baz.com"},
},
},
}
attrs, err = structpb.NewStruct(hostInfo2)
require.NoError(err)
_, err = plg.OnCreateSet(ctx, &plgpb.OnCreateSetRequest{
Set: &hostsets.HostSet{
Id: "set2",
Attrs: &hostsets.HostSet_Attributes{
Attributes: attrs,
},
},
})
require.NoError(err)
// Define test struct and validation function
type testInfo struct {
name string
sets []string
found []any
}
validateSets := func(t *testing.T, tt testInfo) {
require, assert := tr.New(t), ta.New(t)
var hostSets []*hostsets.HostSet
for _, set := range tt.sets {
hostSets = append(hostSets, &hostsets.HostSet{Id: set})
}
resp, err := plg.ListHosts(ctx, &plgpb.ListHostsRequest{
Sets: hostSets,
})
require.NoError(err)
if len(tt.found) == 0 {
assert.Len(resp.GetHosts(), 0)
return
}
require.Greater(len(resp.GetHosts()), 0)
var found []any
for _, host := range resp.GetHosts() {
hostMap := map[string]any{
"external_id": host.GetExternalId(),
}
var sets []any
for _, set := range host.SetIds {
sets = append(sets, set)
}
var ips []any
for _, ip := range host.GetIpAddresses() {
ips = append(ips, ip)
}
var names []any
for _, name := range host.GetDnsNames() {
names = append(names, name)
}
if len(sets) > 0 {
hostMap["set_ids"] = sets
}
if len(ips) > 0 {
hostMap["ip_addresses"] = ips
}
if len(names) > 0 {
hostMap["dns_names"] = names
}
found = append(found, hostMap)
}
assert.ElementsMatch(tt.found, found)
}
// First set of tests: check that we can look up sets individually and
// together
setTests := []testInfo{
{
name: "set 1",
sets: []string{"set1"},
found: hostInfo1[loopbackPluginHostInfoAttrField].([]any),
},
{
name: "set 2",
sets: []string{"set2"},
found: hostInfo2[loopbackPluginHostInfoAttrField].([]any),
},
{
name: "sets 1 and 2",
sets: []string{"set1", "set2"},
found: append(hostInfo1[loopbackPluginHostInfoAttrField].([]any),
hostInfo2[loopbackPluginHostInfoAttrField].([]any)...),
},
}
for _, tt := range setTests {
t.Run(tt.name, func(t *testing.T) {
validateSets(t, tt)
})
}
}
@@ -21,6 +21,7 @@ import (
"github.com/hashicorp/boundary/internal/libs/patchstruct"
"github.com/hashicorp/boundary/internal/oplog"
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/scheduler/job"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
@@ -270,8 +271,8 @@ func TestRepository_CreateCatalog(t *testing.T) {
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
plg.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
NormalizeCatalogDataFn: func(_ context.Context, req *plgpb.NormalizeCatalogDataRequest) (*plgpb.NormalizeCatalogDataResponse, error) {
if req.Attributes == nil {
return new(plgpb.NormalizeCatalogDataResponse), nil
@@ -296,7 +297,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
},
},
},
unimplementedPlugin.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{
unimplementedPlugin.GetPublicId(): &loopback.WrappingPluginClient{Server: &loopback.TestPluginServer{
OnCreateCatalogFn: func(ctx context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
pluginCalled = true
gotPluginAttrs = req.GetCatalog().GetAttributes()
@@ -372,8 +373,8 @@ func TestRepository_CreateCatalog(t *testing.T) {
kms := kms.TestKms(t, conn, wrapper)
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
plg.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
OnCreateCatalogFn: func(_ context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
pluginCalled = true
return &plgpb.OnCreateCatalogResponse{Persisted: &plgpb.HostCatalogPersisted{Secrets: req.GetCatalog().GetSecrets()}}, nil
@@ -418,8 +419,8 @@ func TestRepository_CreateCatalog(t *testing.T) {
kms := kms.TestKms(t, conn, wrapper)
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
plg.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
OnCreateCatalogFn: func(_ context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
pluginCalled = true
return &plgpb.OnCreateCatalogResponse{Persisted: &plgpb.HostCatalogPersisted{Secrets: req.GetCatalog().GetSecrets()}}, nil
@@ -496,8 +497,8 @@ func TestRepository_UpdateCatalog(t *testing.T) {
var pluginError error
testPlugin := hostplugin.TestPlugin(t, dbConn, "test")
testPluginMap := map[string]plgpb.HostPluginServiceClient{
testPlugin.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
testPlugin.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
NormalizeCatalogDataFn: func(_ context.Context, req *plgpb.NormalizeCatalogDataRequest) (*plgpb.NormalizeCatalogDataResponse, error) {
if req.Attributes == nil {
return new(plgpb.NormalizeCatalogDataResponse), nil
@@ -1264,7 +1265,7 @@ func TestRepository_LookupCatalog(t *testing.T) {
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
plg := hostplugin.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}},
plg.GetPublicId(): &loopback.WrappingPluginClient{Server: &loopback.TestPluginServer{}},
}
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
badId, err := newHostCatalogId(ctx)
@@ -1331,7 +1332,7 @@ func TestRepository_ListCatalogs_Multiple_Scopes(t *testing.T) {
sched := scheduler.TestScheduler(t, conn, wrapper)
plg := hostplugin.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}},
plg.GetPublicId(): &loopback.WrappingPluginClient{Server: &loopback.TestPluginServer{}},
}
repo, err := NewRepository(rw, rw, kms, sched, plgm)
assert.NoError(t, err)
@@ -1363,9 +1364,9 @@ func TestRepository_DeleteCatalog(t *testing.T) {
sched := scheduler.TestScheduler(t, conn, wrapper)
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
plg := hostplugin.TestPlugin(t, conn, "test")
pluginInstance := &TestPluginServer{}
pluginInstance := &loopback.TestPluginServer{}
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{Server: pluginInstance},
plg.GetPublicId(): &loopback.WrappingPluginClient{Server: pluginInstance},
}
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
cat2 := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
@@ -1450,7 +1451,7 @@ func TestRepository_DeleteCatalogX(t *testing.T) {
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
plg := hostplugin.TestPlugin(t, conn, "test")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): &WrappingPluginClient{Server: &TestPluginServer{}},
plg.GetPublicId(): &loopback.WrappingPluginClient{Server: &loopback.TestPluginServer{}},
}
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
badId, err := newHostCatalogId(ctx)
@@ -1538,7 +1539,7 @@ func TestRepository_UpdateCatalog_SyncSets(t *testing.T) {
testPlugin := hostplugin.TestPlugin(t, dbConn, "test")
dummyPluginMap := map[string]plgpb.HostPluginServiceClient{
testPlugin.GetPublicId(): &WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}},
testPlugin.GetPublicId(): &loopback.WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}},
}
// Set up a test catalog and the secrets for it
@@ -24,6 +24,7 @@ import (
"github.com/hashicorp/boundary/internal/libs/patchstruct"
"github.com/hashicorp/boundary/internal/oplog"
hostplg "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/mitchellh/mapstructure"
@@ -278,7 +279,7 @@ func TestRepository_CreateSet(t *testing.T) {
}
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(TestPluginServer{
plg.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{
NormalizeSetDataFn: func(_ context.Context, req *plgpb.NormalizeSetDataRequest) (*plgpb.NormalizeSetDataResponse, error) {
if req.Attributes == nil {
return new(plgpb.NormalizeSetDataResponse), nil
@@ -302,7 +303,7 @@ func TestRepository_CreateSet(t *testing.T) {
return &plgpb.OnCreateSetResponse{}, nil
},
}),
unimplementedPlugin.GetPublicId(): NewWrappingPluginClient(TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
unimplementedPlugin.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
pluginCalled = true
pluginReceivedAttrs = req.GetSet().GetAttributes()
return plgpb.UnimplementedHostPluginServiceServer{}.OnCreateSet(ctx, req)
@@ -356,7 +357,7 @@ func TestRepository_CreateSet(t *testing.T) {
assert, require := assert.New(t), require.New(t)
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
plg.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
pluginCalled = true
return &plgpb.OnCreateSetResponse{}, nil
}}),
@@ -399,7 +400,7 @@ func TestRepository_CreateSet(t *testing.T) {
assert, require := assert.New(t), require.New(t)
var pluginCalled bool
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
plg.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
pluginCalled = true
return &plgpb.OnCreateSetResponse{}, nil
}}),
@@ -461,7 +462,7 @@ func TestRepository_UpdateSet(t *testing.T) {
testPlugin := hostplg.TestPlugin(t, dbConn, "test")
dummyPluginMap := map[string]plgpb.HostPluginServiceClient{
testPlugin.GetPublicId(): &WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}},
testPlugin.GetPublicId(): &loopback.WrappingPluginClient{Server: &plgpb.UnimplementedHostPluginServiceServer{}},
}
// Set up a test catalog and the secrets for it
@@ -1199,8 +1200,8 @@ func TestRepository_UpdateSet(t *testing.T) {
// well.
var gotOnUpdateCallCount int
testPluginMap := map[string]plgpb.HostPluginServiceClient{
testPlugin.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
testPlugin.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
NormalizeSetDataFn: func(_ context.Context, req *plgpb.NormalizeSetDataRequest) (*plgpb.NormalizeSetDataResponse, error) {
if req.Attributes == nil {
return new(plgpb.NormalizeSetDataResponse), nil
@@ -1298,8 +1299,8 @@ func TestRepository_UpdateSet(t *testing.T) {
t.Run("Unset Empty PreferredEndpoint", func(t *testing.T) {
var gotOnUpdateCallCount int
testPluginMap := map[string]plgpb.HostPluginServiceClient{
testPlugin.GetPublicId(): &WrappingPluginClient{
Server: &TestPluginServer{
testPlugin.GetPublicId(): &loopback.WrappingPluginClient{
Server: &loopback.TestPluginServer{
OnUpdateSetFn: func(_ context.Context, req *plgpb.OnUpdateSetRequest) (*plgpb.OnUpdateSetResponse, error) {
gotOnUpdateCallCount++
for _, check := range []checkPluginReqFunc{
@@ -1351,12 +1352,12 @@ func TestRepository_LookupSet(t *testing.T) {
_, prj := iam.TestScopes(t, iamRepo)
plg := hostplg.TestPlugin(t, conn, "lookup")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
hostSet := TestSet(t, conn, kms, sched, catalog, map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{
ListHostsFn: func(ctx context.Context, req *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error) {
require.NotEmpty(t, req.GetSets())
require.NotNil(t, req.GetCatalog())
@@ -1422,7 +1423,7 @@ func TestRepository_Endpoints(t *testing.T) {
hostlessCatalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
@@ -1556,7 +1557,7 @@ func TestRepository_ListSets(t *testing.T) {
_, prj := iam.TestScopes(t, iamRepo)
plg := hostplg.TestPlugin(t, conn, "list")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
catalogA := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
catalogB := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
@@ -1628,7 +1629,7 @@ func TestRepository_ListSets_Limits(t *testing.T) {
_, prj := iam.TestScopes(t, iamRepo)
plg := hostplg.TestPlugin(t, conn, "listlimit")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{}),
}
catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
count := 10
@@ -1708,7 +1709,7 @@ func TestRepository_DeleteSet(t *testing.T) {
plg := hostplg.TestPlugin(t, conn, "create")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
plg.GetPublicId(): loopback.NewWrappingPluginClient(loopback.TestPluginServer{OnCreateSetFn: func(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
return &plgpb.OnCreateSetResponse{}, nil
}}),
}
+2 -1
View File
@@ -21,6 +21,7 @@ import (
"github.com/hashicorp/boundary/internal/oplog"
hostplg "github.com/hashicorp/boundary/internal/plugin/host"
hostplgstore "github.com/hashicorp/boundary/internal/plugin/host/store"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/stretchr/testify/assert"
@@ -39,7 +40,7 @@ func TestJob_UpsertHosts(t *testing.T) {
plg := hostplg.TestPlugin(t, conn, "create")
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}),
plg.GetPublicId(): loopback.NewWrappingPluginClient(&plgpb.UnimplementedHostPluginServiceServer{}),
}
catalog := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
-79
View File
@@ -231,82 +231,3 @@ func testGetIpAddress(t testing.TB) string {
}
}
}
var _ plgpb.HostPluginServiceServer = (*TestPluginServer)(nil)
// TestPluginServer provides a host plugin service server where each method can be overwritten for tests.
type TestPluginServer struct {
NormalizeCatalogDataFn func(context.Context, *plgpb.NormalizeCatalogDataRequest) (*plgpb.NormalizeCatalogDataResponse, error)
OnCreateCatalogFn func(context.Context, *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error)
OnUpdateCatalogFn func(context.Context, *plgpb.OnUpdateCatalogRequest) (*plgpb.OnUpdateCatalogResponse, error)
OnDeleteCatalogFn func(context.Context, *plgpb.OnDeleteCatalogRequest) (*plgpb.OnDeleteCatalogResponse, error)
NormalizeSetDataFn func(context.Context, *plgpb.NormalizeSetDataRequest) (*plgpb.NormalizeSetDataResponse, error)
OnCreateSetFn func(context.Context, *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error)
OnUpdateSetFn func(context.Context, *plgpb.OnUpdateSetRequest) (*plgpb.OnUpdateSetResponse, error)
OnDeleteSetFn func(context.Context, *plgpb.OnDeleteSetRequest) (*plgpb.OnDeleteSetResponse, error)
ListHostsFn func(context.Context, *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error)
plgpb.UnimplementedHostPluginServiceServer
}
func (t TestPluginServer) NormalizeCatalogData(ctx context.Context, req *plgpb.NormalizeCatalogDataRequest) (*plgpb.NormalizeCatalogDataResponse, error) {
if t.NormalizeCatalogDataFn == nil {
return t.UnimplementedHostPluginServiceServer.NormalizeCatalogData(ctx, req)
}
return t.NormalizeCatalogDataFn(ctx, req)
}
func (t TestPluginServer) OnCreateCatalog(ctx context.Context, req *plgpb.OnCreateCatalogRequest) (*plgpb.OnCreateCatalogResponse, error) {
if t.OnCreateCatalogFn == nil {
return t.UnimplementedHostPluginServiceServer.OnCreateCatalog(ctx, req)
}
return t.OnCreateCatalogFn(ctx, req)
}
func (t TestPluginServer) OnUpdateCatalog(ctx context.Context, req *plgpb.OnUpdateCatalogRequest) (*plgpb.OnUpdateCatalogResponse, error) {
if t.OnUpdateCatalogFn == nil {
return t.UnimplementedHostPluginServiceServer.OnUpdateCatalog(ctx, req)
}
return t.OnUpdateCatalogFn(ctx, req)
}
func (t TestPluginServer) OnDeleteCatalog(ctx context.Context, req *plgpb.OnDeleteCatalogRequest) (*plgpb.OnDeleteCatalogResponse, error) {
if t.OnDeleteCatalogFn == nil {
return t.UnimplementedHostPluginServiceServer.OnDeleteCatalog(ctx, req)
}
return t.OnDeleteCatalogFn(ctx, req)
}
func (t TestPluginServer) NormalizeSetData(ctx context.Context, req *plgpb.NormalizeSetDataRequest) (*plgpb.NormalizeSetDataResponse, error) {
if t.NormalizeSetDataFn == nil {
return t.UnimplementedHostPluginServiceServer.NormalizeSetData(ctx, req)
}
return t.NormalizeSetDataFn(ctx, req)
}
func (t TestPluginServer) OnCreateSet(ctx context.Context, req *plgpb.OnCreateSetRequest) (*plgpb.OnCreateSetResponse, error) {
if t.OnCreateSetFn == nil {
return t.UnimplementedHostPluginServiceServer.OnCreateSet(ctx, req)
}
return t.OnCreateSetFn(ctx, req)
}
func (t TestPluginServer) OnUpdateSet(ctx context.Context, req *plgpb.OnUpdateSetRequest) (*plgpb.OnUpdateSetResponse, error) {
if t.OnUpdateSetFn == nil {
return t.UnimplementedHostPluginServiceServer.OnUpdateSet(ctx, req)
}
return t.OnUpdateSetFn(ctx, req)
}
func (t TestPluginServer) OnDeleteSet(ctx context.Context, req *plgpb.OnDeleteSetRequest) (*plgpb.OnDeleteSetResponse, error) {
if t.OnDeleteSetFn == nil {
return t.UnimplementedHostPluginServiceServer.OnDeleteSet(ctx, req)
}
return t.OnDeleteSetFn(ctx, req)
}
func (t TestPluginServer) ListHosts(ctx context.Context, req *plgpb.ListHostsRequest) (*plgpb.ListHostsResponse, error) {
if t.ListHostsFn == nil {
return t.UnimplementedHostPluginServiceServer.ListHosts(ctx, req)
}
return t.ListHostsFn(ctx, req)
}
+5 -4
View File
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/plugin/loopback"
"github.com/hashicorp/boundary/internal/scheduler"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/stretchr/testify/assert"
@@ -52,7 +53,7 @@ func Test_TestSet(t *testing.T) {
assert.NotEmpty(plg.GetPublicId())
c := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId())
set := TestSet(t, conn, kmsCache, sched, c, map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{})}, WithName("foo"), WithDescription("bar"))
set := TestSet(t, conn, kmsCache, sched, c, map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{})}, WithName("foo"), WithDescription("bar"))
assert.NotEmpty(set.GetPublicId())
db.AssertPublicId(t, globals.PluginHostSetPrefix, set.GetPublicId())
assert.Equal("foo", set.GetName())
@@ -93,7 +94,7 @@ func Test_TestSetMembers(t *testing.T) {
assert.NotEmpty(plg.GetPublicId())
c := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId())
s := TestSet(t, conn, kmsCache, sched, c, map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{})})
s := TestSet(t, conn, kmsCache, sched, c, map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): loopback.NewWrappingPluginClient(&loopback.TestPluginServer{})})
h := TestHost(t, conn, c.GetPublicId(), plg.GetPublicId())
members := TestSetMembers(t, conn, s.PublicId, []*Host{h})
@@ -115,8 +116,8 @@ func Test_TestRunSetSync(t *testing.T) {
plg := host.TestPlugin(t, conn, "test")
require.NotNil(plg)
assert.NotEmpty(plg.GetPublicId())
pluginServer := &TestPluginServer{}
plgm := map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): NewWrappingPluginClient(pluginServer)}
pluginServer := &loopback.TestPluginServer{}
plgm := map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): loopback.NewWrappingPluginClient(pluginServer)}
c := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId())
s1 := TestSet(t, conn, kmsCache, sched, c, plgm)