From 04871ea2db6f60822e43492ffc08e042c6eb4cf2 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Mon, 3 Jul 2023 20:28:02 +0300
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/setup/collection_test.go | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/pkg/setup/collection_test.go b/pkg/setup/collection_test.go
index 2b9f8e4c..027c13b9 100644
--- a/pkg/setup/collection_test.go
+++ b/pkg/setup/collection_test.go
@@ -23,6 +23,7 @@ func TestSetup_InstallCollections(t *testing.T) {
 		collectionsCall func(svc *mockscollections.Collections)
 		envsCall        func(svc *envmocks.Environments)
 		co              CollectionsOption
+		force           bool
 		wantErr         func(t *testing.T, err error)
 	}{
 		{
@@ -119,6 +120,23 @@ func TestSetup_InstallCollections(t *testing.T) {
 			},
 			co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}),
 		},
+		{
+			name:        "Update collection with the same id, with force",
+			collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata("extension", "test-extension")}},
+			collectionsCall: func(svc *mockscollections.Collections) {
+				svc.On("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata("extension", "test-extension")}, nil).Once()
+				svc.On("Update", mock.Anything, &collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata("extension", "test-extension")}).Return(nil).Once()
+				svc.On("SetSchema", mock.Anything, "sp", "env", "1", schema.New("name", field.String())).Return(nil).Once()
+			},
+			envsCall: func(svc *envmocks.Environments) {
+				svc.On("Migrate", mock.Anything, "sp", "env", &environments.MigrateOptions{Wait: true}).Return(nil).Once()
+			},
+			wantErr: func(t *testing.T, err error) {
+				assert.NoError(t, err)
+			},
+			co:    SetSchemaMetadata(map[string]string{"extension": "test-extension"}),
+			force: true,
+		},
 	}
 
 	for _, tt := range tests {
@@ -133,6 +151,7 @@ func TestSetup_InstallCollections(t *testing.T) {
 			}
 
 			s := NewSetup(&content.Content{Collections: c, Environments: e}, "sp", "env", nil)
+			s.force = tt.force
 			if tt.co != nil {
 				s.AddCollections(tt.collections, tt.co)
 			} else {
-- 
GitLab