Skip to content
Snippets Groups Projects
Commit 868c35fe authored by ko_oler's avatar ko_oler
Browse files

- изменен тип metadata в CollectionConfig на []string

- изменена сигнатура функции SetSchemaMetadata
- мелкие правки
parent 286034c6
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool ...@@ -23,7 +23,7 @@ type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool
type CollectionConfig struct { type CollectionConfig struct {
collection *collections.Collection collection *collections.Collection
metadata map[string]string metadata []string
UpdateFn UpdateCollectionFn UpdateFn UpdateCollectionFn
DeleteFn DeleteCollectionFn DeleteFn DeleteCollectionFn
} }
...@@ -81,9 +81,9 @@ func UpdateExistingCollection() CollectionsOption { ...@@ -81,9 +81,9 @@ func UpdateExistingCollection() CollectionsOption {
} }
} }
func SetSchemaMetadata(md map[string]string) CollectionsOption { func SetSchemaMetadata(kv ...string) CollectionsOption {
return func(c *CollectionConfig) { return func(c *CollectionConfig) {
c.metadata = md c.metadata = kv
} }
} }
...@@ -147,7 +147,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -147,7 +147,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
} else { } else {
var upd bool var upd bool
if c.metadata != nil { if c.metadata != nil {
collection.Schema.Metadata = c.metadata collection.Schema.WithMetadata(c.metadata...)
err = s.checkSchemaMetadata(collection, exist) err = s.checkSchemaMetadata(collection, exist)
if err != nil { if err != nil {
return false, err return false, err
...@@ -172,14 +172,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -172,14 +172,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
return setSchema, nil return setSchema, nil
} }
// checkSchemaMetadata проверяет изменилось ли значение Metadata в схеме коллекции
func (s *Setup) checkSchemaMetadata(collection *collections.Collection, exist *collections.Collection) error { func (s *Setup) checkSchemaMetadata(collection *collections.Collection, exist *collections.Collection) error {
if collection.Schema.Metadata != nil { if collection.Schema.Metadata != nil {
if _, ok := collection.Schema.Metadata["extension"]; ok { if exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() {
if _, ok := exist.Schema.Metadata["extension"]; !ok && !s.IsForce() {
return errors.WithHint(errors.New("fail to update collection"), "collection has the same id as extension's collection, change yours collection id") return errors.WithHint(errors.New("fail to update collection"), "collection has the same id as extension's collection, change yours collection id")
} }
} }
}
return nil return nil
} }
......
...@@ -107,7 +107,7 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -107,7 +107,7 @@ func TestSetup_InstallCollections(t *testing.T) {
wantErr: func(t *testing.T, err error) { wantErr: func(t *testing.T, err error) {
assert.NoError(t, err) assert.NoError(t, err)
}, },
co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), co: SetSchemaMetadata("extension", "test-extension"),
}, },
{ {
name: "Fail to update collection with the same id", name: "Fail to update collection with the same id",
...@@ -118,7 +118,7 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -118,7 +118,7 @@ func TestSetup_InstallCollections(t *testing.T) {
wantErr: func(t *testing.T, err error) { wantErr: func(t *testing.T, err error) {
assert.Error(t, err) assert.Error(t, err)
}, },
co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), co: SetSchemaMetadata("extension", "test-extension"),
}, },
{ {
name: "Update collection with the same id, with force", name: "Update collection with the same id, with force",
...@@ -134,7 +134,7 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -134,7 +134,7 @@ func TestSetup_InstallCollections(t *testing.T) {
wantErr: func(t *testing.T, err error) { wantErr: func(t *testing.T, err error) {
assert.NoError(t, err) assert.NoError(t, err)
}, },
co: SetSchemaMetadata(map[string]string{"extension": "test-extension"}), co: SetSchemaMetadata("extension", "test-extension"),
force: true, force: true,
}, },
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment