Skip to content
Snippets Groups Projects
Commit 4e33d768 authored by ko_oler's avatar ko_oler
Browse files

- поднята версия хранилища

- обновлена логика функции InstallCollection с учетом добавления поля Metadata
- добавлены тест
parent 41851bbd
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ type Content struct { ...@@ -39,7 +39,7 @@ type Content struct {
} }
const ( const (
DBVersion uint32 = 2 DBVersion uint32 = 3
) )
func (c *Content) RegisterStart(svc interface{}) { func (c *Content) RegisterStart(svc interface{}) {
......
...@@ -139,6 +139,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -139,6 +139,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
} }
} else { } else {
var upd bool var upd bool
if _, ok := collection.Schema.Metadata["extension"]; ok {
if _, ok := exist.Schema.Metadata["extension"]; !ok {
return false, errors.WithHint(errors.New("fail to update collection"), "collection has the same id as extension's collection, change yours collection id")
}
}
collection, upd, setSchema = c.UpdateFn(s, exist, c.collection) collection, upd, setSchema = c.UpdateFn(s, exist, c.collection)
if upd { if upd {
if err = s.content.Collections.Update(ctx, collection); err != nil { if err = s.content.Collections.Update(ctx, collection); err != nil {
......
...@@ -91,6 +91,31 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -91,6 +91,31 @@ func TestSetup_InstallCollections(t *testing.T) {
assert.Contains(t, errors.GetDetail(err), "Возникла ошибка при настройке коллекции space(1)") assert.Contains(t, errors.GetDetail(err), "Возникла ошибка при настройке коллекции space(1)")
}, },
}, },
{
name: "Update extension collection with metadata",
collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: &schema.Schema{Field: schema.New("name", field.String()).Field, Metadata: map[string]string{"extension": "tasks"}}}},
collectionsCall: func(svc *mockscollections.Collections) {
svc.On("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: &schema.Schema{Field: schema.New("name", field.String()).Field, Metadata: map[string]string{"extension": "tasks"}}}, nil).Once()
svc.On("Update", mock.Anything, &collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: &schema.Schema{Field: schema.New("name", field.String()).Field, Metadata: map[string]string{"extension": "tasks"}}}).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)
},
},
{
name: "Fail to update collection with the same id",
collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: &schema.Schema{Field: schema.New("name", field.String()).Field, Metadata: map[string]string{"extension": "tasks"}}}},
collectionsCall: func(svc *mockscollections.Collections) {
svc.On("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: &schema.Schema{Field: schema.New("surname", field.String()).Field}}, nil).Once()
},
wantErr: func(t *testing.T, err error) {
assert.Error(t, err)
},
},
} }
for _, tt := range tests { for _, tt := range tests {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment