Remove Prefix Id and Plugin Name fields (#1563)
* 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.
This commit is contained in:
51 files changed
+1314
-1052
No files matched your search
@@ -41,39 +41,18 @@ func TestRepository_CreatePlugin(t *testing.T) {
|
||||
in: &Plugin{},
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "valid-no-options",
|
||||
in: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validnooptions",
|
||||
PluginName: "validnooptions",
|
||||
},
|
||||
},
|
||||
want: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validnooptions",
|
||||
PluginName: "validnooptions",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid-with-name",
|
||||
in: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
Name: "test-name-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validwithname",
|
||||
PluginName: "validwithname",
|
||||
Name: "test-name-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
},
|
||||
},
|
||||
want: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
Name: "test-name-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validwithname",
|
||||
PluginName: "validwithname",
|
||||
Name: "test-name-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -83,37 +62,20 @@ func TestRepository_CreatePlugin(t *testing.T) {
|
||||
Plugin: &store.Plugin{
|
||||
Description: "test-description-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validwithdescription",
|
||||
PluginName: "validwithdescription",
|
||||
},
|
||||
},
|
||||
want: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
Description: "test-description-repo",
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "validwithdescription",
|
||||
PluginName: "validwithdescription",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "mismatching-prefix-plugin-name",
|
||||
in: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "foo",
|
||||
PluginName: "bar",
|
||||
},
|
||||
},
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "non-global-scope",
|
||||
in: &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: "o_1234567890",
|
||||
IdPrefix: "foo",
|
||||
PluginName: "foo",
|
||||
ScopeId: "o_1234567890",
|
||||
},
|
||||
},
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
@@ -150,38 +112,8 @@ func TestRepository_CreatePlugin(t *testing.T) {
|
||||
assert.NotNil(repo)
|
||||
in := &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "invalidduplicatenames",
|
||||
PluginName: "invalidduplicatenames",
|
||||
Name: "invalid-duplicate-names",
|
||||
},
|
||||
}
|
||||
|
||||
got, err := repo.CreatePlugin(context.Background(), in)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(got)
|
||||
assertPublicId(t, PluginPrefix, got.PublicId)
|
||||
assert.NotSame(in, got)
|
||||
assert.Equal(in.Name, got.Name)
|
||||
assert.Equal(in.Description, got.Description)
|
||||
assert.Equal(got.CreateTime, got.UpdateTime)
|
||||
|
||||
got2, err := repo.CreatePlugin(context.Background(), in)
|
||||
assert.Truef(errors.Match(errors.T(errors.NotUnique), err), "want err code: %v got err: %v", errors.NotUnique, err)
|
||||
assert.Nil(got2)
|
||||
})
|
||||
|
||||
t.Run("invalid-duplicate-plugin-names-prefixes", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
repo, err := NewRepository(rw, rw, kms)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(repo)
|
||||
in := &Plugin{
|
||||
Plugin: &store.Plugin{
|
||||
ScopeId: scope.Global.String(),
|
||||
IdPrefix: "invalidduplicatepluginnames",
|
||||
PluginName: "invalidduplicatepluginnames",
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: "invalid-duplicate-names",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -212,7 +144,7 @@ func TestRepository_LookupPlugin(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
plg := TestPlugin(t, conn, "test", "test")
|
||||
plg := TestPlugin(t, conn, "test")
|
||||
badId, err := newPluginId()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, badId)
|
||||
@@ -268,11 +200,11 @@ func TestRepository_LookupPlugin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepository_LookupPluginByPluginName(t *testing.T) {
|
||||
func TestRepository_LookupPluginByName(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrapper := db.TestWrapper(t)
|
||||
plg := TestPlugin(t, conn, "name123", "name123")
|
||||
plg := TestPlugin(t, conn, "name123")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -282,7 +214,7 @@ func TestRepository_LookupPluginByPluginName(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "found",
|
||||
pluginName: plg.GetPluginName(),
|
||||
pluginName: plg.GetName(),
|
||||
want: plg,
|
||||
},
|
||||
{
|
||||
@@ -307,7 +239,7 @@ func TestRepository_LookupPluginByPluginName(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
assert.NotNil(repo)
|
||||
|
||||
got, err := repo.LookupPluginByPluginName(context.Background(), tt.pluginName)
|
||||
got, err := repo.LookupPluginByName(context.Background(), tt.pluginName)
|
||||
if tt.wantErr != 0 {
|
||||
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user