diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go index a2922a0d44a2232dafe5a07f74662873d2ff4c98..09c13cd13308c86a1eb7362d120d91b424dfdb89 100644 --- a/pkg/setup/collection.go +++ b/pkg/setup/collection.go @@ -23,7 +23,7 @@ type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool type CollectionConfig struct { collection *collections.Collection - metadata []string + metadata map[string]string UpdateFn UpdateCollectionFn DeleteFn DeleteCollectionFn } @@ -81,9 +81,9 @@ func UpdateExistingCollection() CollectionsOption { } } -func SetSchemaMetadata(kv ...string) CollectionsOption { +func SetSchemaMetadata(md map[string]string) CollectionsOption { return func(c *CollectionConfig) { - c.metadata = kv + c.metadata = md } } @@ -139,7 +139,9 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS } if c.metadata != nil { - collection.Schema.WithMetadata(c.metadata...) + for k, v := range c.metadata { + collection.Schema.WithMetadata(k, v) + } } if exist == nil { @@ -150,7 +152,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS } } else { if collection.Schema.Metadata != nil && exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() { - return false, errors.Wrap(errors.Errorf("collection %s has the same id(%s) as extension's collection %s", exist.Name, exist.ID, collection.Name), "fail to update collection") + return false, errors.New("collection already exists") } var upd bool diff --git a/pkg/setup/collection_test.go b/pkg/setup/collection_test.go index a3a6bafa3cfa0e874e3374c33f0e6fe94cfd8ca2..027c13b9ea51c566076cc8c5fa9a3f31814f4273 100644 --- a/pkg/setup/collection_test.go +++ b/pkg/setup/collection_test.go @@ -107,7 +107,7 @@ func TestSetup_InstallCollections(t *testing.T) { wantErr: func(t *testing.T, err error) { assert.NoError(t, err) }, - co: SetSchemaMetadata("extension", "test-extension"), + co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), }, { name: "Fail to update collection with the same id", @@ -118,7 +118,7 @@ func TestSetup_InstallCollections(t *testing.T) { wantErr: func(t *testing.T, err error) { assert.Error(t, err) }, - co: SetSchemaMetadata("extension", "test-extension"), + co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), }, { name: "Update collection with the same id, with force", @@ -134,7 +134,7 @@ func TestSetup_InstallCollections(t *testing.T) { wantErr: func(t *testing.T, err error) { assert.NoError(t, err) }, - co: SetSchemaMetadata("extension", "test-extension"), + co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), force: true, }, }