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

правки по ПР

parent e19c968f
Branches
Tags
No related merge requests found
...@@ -15,6 +15,7 @@ var ( ...@@ -15,6 +15,7 @@ var (
ErrCheckCollections = errors.New("collections check error") ErrCheckCollections = errors.New("collections check error")
ErrInstallCollections = errors.New("failed to install collections") ErrInstallCollections = errors.New("failed to install collections")
ErrUninstallCollections = errors.New("failed to uninstall collections") ErrUninstallCollections = errors.New("failed to uninstall collections")
ErrCollectionAlreadyExists = errors.New("failed to uninstall collections")
) )
type CollectionsOption func(c *CollectionConfig) type CollectionsOption func(c *CollectionConfig)
...@@ -81,9 +82,14 @@ func UpdateExistingCollection() CollectionsOption { ...@@ -81,9 +82,14 @@ 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 if c.metadata == nil {
c.metadata = make(map[string]string)
}
for i := 0; i < len(kv); i += 2 {
c.metadata[kv[i]] = kv[i+1]
}
} }
} }
...@@ -152,7 +158,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -152,7 +158,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.New("collection already exists") return false, ErrCollectionAlreadyExists
} }
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(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