From e19c968fec118c2d146e76dc79b8947b1b4a99d4 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Fri, 7 Jul 2023 12:25:18 +0300
Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?=
 =?UTF-8?q?=D0=BE=20=D0=9F=D0=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/setup/collection.go      | 12 +++++++-----
 pkg/setup/collection_test.go |  6 +++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/pkg/setup/collection.go b/pkg/setup/collection.go
index a2922a0d..09c13cd1 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 a3a6bafa..027c13b9 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,
 		},
 	}
-- 
GitLab