Placeholder Plugin Providers for Repos and added testPlugin struct (#1532)
* Create minimalistic plugin map and test plugin. * Pass secrets and attributes to the plugin when creating catalogs or sets. Add tests for CreateSet and CreateCatalog repo methods. * make fmt and extract out getPrivateCatalog and getCatalog helper methods. * Exporting TestPluginServer so it can be used in the handlers. * Keep separate persisted data from host catalogs lookups which facilitate passing it onto the plugins. * Add TODO to merge get Catalog and get Persisted data. * Adding tests for unimplemented being returned by the plugin. * Use GetFields() instead of AsMap() to confirm attributes should be populated. Make clone consistent between catalog and sets. Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
This commit is contained in:
1 parent
ea939a4445
commit
bbfef2802f
30 files changed
+669
-227
No files matched your search
@@ -2,7 +2,6 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -14,7 +13,9 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/plugin/host"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
func TestHostCatalogSecret_New(t *testing.T) {
|
||||
@@ -28,7 +29,7 @@ func TestHostCatalogSecret_New(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
catalogId string
|
||||
attrs map[string]interface{}
|
||||
attrs *structpb.Struct
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -64,13 +65,19 @@ func TestHostCatalogSecret_New(t *testing.T) {
|
||||
name: "valid",
|
||||
args: args{
|
||||
catalogId: cat.GetPublicId(),
|
||||
attrs: map[string]interface{}{"foo": "bar"},
|
||||
attrs: func() *structpb.Struct {
|
||||
st, err := structpb.NewStruct(map[string]interface{}{"foo": "bar"})
|
||||
require.NoError(t, err)
|
||||
return st
|
||||
}(),
|
||||
},
|
||||
want: &HostCatalogSecret{
|
||||
HostCatalogSecret: &store.HostCatalogSecret{
|
||||
CatalogId: cat.GetPublicId(),
|
||||
Secret: func() []byte {
|
||||
b, err := json.Marshal(map[string]interface{}{"foo": "bar"})
|
||||
st, err := structpb.NewStruct(map[string]interface{}{"foo": "bar"})
|
||||
require.NoError(t, err)
|
||||
b, err := proto.Marshal(st)
|
||||
require.NoError(t, err)
|
||||
return b
|
||||
}(),
|
||||
@@ -124,7 +131,8 @@ func TestHostCatalogSecret_Custom_Queries(t *testing.T) {
|
||||
databaseWrapper, err := kkms.GetWrapper(ctx, prj.PublicId, kms.KeyPurposeDatabase)
|
||||
require.NoError(t, err)
|
||||
|
||||
hcs, err := newHostCatalogSecret(ctx, cat.GetPublicId(), map[string]interface{}{"foo": "bar"})
|
||||
hcs, err := newHostCatalogSecret(ctx, cat.GetPublicId(),
|
||||
&structpb.Struct{Fields: map[string]*structpb.Value{"foo": structpb.NewStringValue("bar")}})
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, hcs.encrypt(ctx, databaseWrapper))
|
||||
q, v := hcs.insertQuery()
|
||||
@@ -141,7 +149,8 @@ func TestHostCatalogSecret_Custom_Queries(t *testing.T) {
|
||||
assert.Empty(t, cmp.Diff(hcs, found, protocmp.Transform()))
|
||||
|
||||
// Update the secret and see the value updated.
|
||||
updated, err := newHostCatalogSecret(ctx, cat.GetPublicId(), map[string]interface{}{"updated": "value"})
|
||||
updated, err := newHostCatalogSecret(ctx, cat.GetPublicId(),
|
||||
&structpb.Struct{Fields: map[string]*structpb.Value{"updated": structpb.NewStringValue("value")}})
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, updated.encrypt(ctx, databaseWrapper))
|
||||
q, v = updated.insertQuery()
|
||||
|
||||
Reference in new issue
Block a user