Fix secrets clearing bug in update. Changes to update count behavior for catalogs (#1691)

* Fix secret clearing bug in update.  Always return 1 catalog updated if we can find a catalog w/ a matching version.
This commit is contained in:
Todd authored and GitHub committed 2021-11-12 09:46:40 -07:00
1 parent 5cfcc41f00
commit b16ce175e5
6 files changed
+88 -15

No files matched your search

@@ -1354,7 +1354,7 @@ func TestUpdate_Plugin(t *testing.T) {
name := "test"
plg := host.TestPlugin(t, conn, name)
plgm := map[string]plgpb.HostPluginServiceClient{
plg.GetPublicId(): plugin.NewWrappingPluginClient(&plugin.TestPluginServer{}),
plg.GetPublicId(): plugin.NewWrappingPluginClient(plugin.NewLoopbackPlugin()),
}
repoFn := func() (*static.Repository, error) {
@@ -1422,6 +1422,11 @@ func TestUpdate_Plugin(t *testing.T) {
c.Attributes = i
}
}
updateSecrets := func(i *structpb.Struct) updateFn {
return func(c *pb.HostCatalog) {
c.Secrets = i
}
}
cases := []struct {
name string
@@ -1461,6 +1466,20 @@ func TestUpdate_Plugin(t *testing.T) {
assert.Equal(t, map[string]interface{}{"newkey": "newvalue"}, in.GetAttributes().AsMap())
},
},
{
name: "Update secrets",
masks: []string{"secrets.key1", "secrets.key2"},
changes: []updateFn{
clearReadOnlyFields(),
updateSecrets(func() *structpb.Struct {
attr, err := structpb.NewStruct(map[string]interface{}{
"key1": "val1",
})
require.NoError(t, err)
return attr
}()),
},
},
{
name: "Multiple Paths in single string",
masks: []string{"name,description"},
@@ -1615,7 +1634,9 @@ func TestUpdate_Plugin(t *testing.T) {
item := got.GetItem()
assert.Equal(uint32(2), item.GetVersion())
assert.Greater(item.GetUpdatedTime().AsTime().UnixNano(), item.GetCreatedTime().AsTime().UnixNano())
tc.check(t, item)
if tc.check != nil {
tc.check(t, item)
}
})
}
}