* Remove Prefix Id and Plugin Name fields. Creating catalogs now require either the plugin id or the name of the plugin resource (but not both). Host Catalogs and Host Sets API resources now have a read only plugin field populated with plugin info. Host Catalogs have a plugin id field as a top level field.
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package host
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
"github.com/hashicorp/boundary/internal/db/timestamp"
|
|
"github.com/hashicorp/boundary/internal/plugin/host/store"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/proto"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func TestHostPlugin_ImmutableFields(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
w := db.New(conn)
|
|
|
|
ts := timestamp.Timestamp{Timestamp: ×tamppb.Timestamp{Seconds: 0, Nanos: 0}}
|
|
plg := TestPlugin(t, conn, "test")
|
|
|
|
newPlugin := plg
|
|
|
|
tests := []struct {
|
|
name string
|
|
update *Plugin
|
|
fieldMask []string
|
|
}{
|
|
{
|
|
name: "public_id",
|
|
update: func() *Plugin {
|
|
c := newPlugin.testClonePlugin()
|
|
c.PublicId = "hc_thisIsNotAValidId"
|
|
return c
|
|
}(),
|
|
fieldMask: []string{"PublicId"},
|
|
},
|
|
{
|
|
name: "create time",
|
|
update: func() *Plugin {
|
|
c := newPlugin.testClonePlugin()
|
|
c.CreateTime = &ts
|
|
return c
|
|
}(),
|
|
fieldMask: []string{"CreateTime"},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
orig := newPlugin.testClonePlugin()
|
|
err := w.LookupById(context.Background(), orig)
|
|
require.NoError(err)
|
|
|
|
rowsUpdated, err := w.Update(context.Background(), tt.update, tt.fieldMask, nil, db.WithSkipVetForWrite(true))
|
|
require.Error(err)
|
|
assert.Equal(0, rowsUpdated)
|
|
|
|
after := newPlugin.testClonePlugin()
|
|
err = w.LookupById(context.Background(), after)
|
|
require.NoError(err)
|
|
|
|
assert.True(proto.Equal(orig, after))
|
|
})
|
|
}
|
|
}
|
|
|
|
func (c *Plugin) testClonePlugin() *Plugin {
|
|
cp := proto.Clone(c.Plugin)
|
|
return &Plugin{
|
|
Plugin: cp.(*store.Plugin),
|
|
}
|
|
}
|