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

правки по ПР

parent 821bb1a9
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 []string metadata map[string]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(kv ...string) CollectionsOption { func SetSchemaMetadata(md map[string]string) CollectionsOption {
return func(c *CollectionConfig) { return func(c *CollectionConfig) {
c.metadata = kv c.metadata = md
} }
} }
...@@ -139,7 +139,9 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -139,7 +139,9 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
} }
if c.metadata != nil { if c.metadata != nil {
collection.Schema.WithMetadata(c.metadata...) for k, v := range c.metadata {
collection.Schema.WithMetadata(k, v)
}
} }
if exist == nil { if exist == nil {
...@@ -150,7 +152,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -150,7 +152,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
} }
} else { } else {
if collection.Schema.Metadata != nil && exist.Schema.Metadata["extension"] != collection.Schema.Metadata["extension"] && !s.IsForce() { 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 var upd bool
......
...@@ -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("extension", "test-extension"), co: SetSchemaMetadata(map[string]string{"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("extension", "test-extension"), co: SetSchemaMetadata(map[string]string{"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("extension", "test-extension"), co: SetSchemaMetadata(map[string]string{"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