Add update catalog support for plugin based catalogs in handler and go sdk (#1673)
* Create catalog service handler for updating plugin. Add tests for handler and run make fmt. Silently drop attributes where the value is nil when creating the catalog or set.
This commit is contained in:
12 files changed
+437
-23
No files matched your search
@@ -1,8 +1,12 @@
|
||||
package patchstruct
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/hashicorp/boundary/internal/host"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
@@ -75,6 +79,24 @@ var testCases = []testCase{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nested with nil",
|
||||
dst: nil,
|
||||
src: map[string]interface{}{
|
||||
"a": "b",
|
||||
"nested": map[string]interface{}{
|
||||
"c": "d",
|
||||
"e": nil,
|
||||
},
|
||||
"f": nil,
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"a": "b",
|
||||
"nested": map[string]interface{}{
|
||||
"c": "d",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "overwrite with map in src",
|
||||
dst: map[string]interface{}{
|
||||
@@ -111,6 +133,17 @@ var testCases = []testCase{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nil dst with src nil value",
|
||||
dst: nil,
|
||||
src: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"fiz": nil,
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestPatchStruct(t *testing.T) {
|
||||
@@ -130,7 +163,11 @@ func TestPatchStruct(t *testing.T) {
|
||||
}
|
||||
|
||||
actual := PatchStruct(dst, src)
|
||||
require.Equal(mustStruct(tc.expected), actual)
|
||||
require.Empty(cmp.Diff(mustStruct(tc.expected), actual,
|
||||
cmpopts.IgnoreUnexported(structpb.Struct{}, structpb.Value{}),
|
||||
cmpopts.SortSlices(func(x, y interface{}) bool {
|
||||
return x.(*host.IpAddress).Address < y.(*host.IpAddress).Address
|
||||
})))
|
||||
require.Equal(dstOrig, dst)
|
||||
require.Equal(srcOrig, src)
|
||||
})
|
||||
@@ -155,12 +192,14 @@ func TestPatchBytesErr(t *testing.T) {
|
||||
t.Run("dst", func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
_, err := PatchBytes([]byte("foo"), nil)
|
||||
require.EqualError(err, "error reading destination data: proto: cannot parse invalid wire-format data")
|
||||
require.ErrorIs(err, proto.Error)
|
||||
require.True(strings.HasPrefix(err.Error(), "error reading destination data: "))
|
||||
})
|
||||
t.Run("src", func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
_, err := PatchBytes(nil, []byte("foo"))
|
||||
require.EqualError(err, "error reading source data: proto: cannot parse invalid wire-format data")
|
||||
require.ErrorIs(err, proto.Error)
|
||||
require.True(strings.HasPrefix(err.Error(), "error reading source data: "))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user