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

- revert InstallСollection()

- убраны лишние тесты
parent 3f95e04e
Branches
Tags
No related merge requests found
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/collections"
"git.perx.ru/perxis/perxis-go/pkg/environments" "git.perx.ru/perxis/perxis-go/pkg/environments"
"git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/extension"
"go.uber.org/zap" "go.uber.org/zap"
) )
...@@ -83,17 +82,6 @@ func UpdateExistingCollection() CollectionsOption { ...@@ -83,17 +82,6 @@ func UpdateExistingCollection() CollectionsOption {
} }
} }
func SetSchemaMetadata(kv ...string) CollectionsOption {
return func(c *CollectionConfig) {
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]
}
}
}
func (s *Setup) InstallCollections(ctx context.Context) (err error) { func (s *Setup) InstallCollections(ctx context.Context) (err error) {
if len(s.Collections) == 0 { if len(s.Collections) == 0 {
return nil return nil
...@@ -145,13 +133,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -145,13 +133,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
return false, err return false, err
} }
if !collection.IsView() {
for k, v := range c.metadata {
collection.Schema.WithMetadata(k, v)
}
//setMD = true
}
if exist == nil { if exist == nil {
setSchema = !collection.IsView() setSchema = !collection.IsView()
_, err = s.content.Collections.Create(ctx, collection) _, err = s.content.Collections.Create(ctx, collection)
...@@ -159,11 +140,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -159,11 +140,6 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
return false, err return false, err
} }
} else { } else {
if !collection.IsView() && !exist.IsView() {
if collection.Schema.Metadata != nil && exist.Schema.Metadata[extension.ExtensionMetadataKey] != collection.Schema.Metadata[extension.ExtensionMetadataKey] && !s.IsForce() {
return false, ErrCollectionAlreadyExists
}
}
var upd bool var upd bool
collection, upd, setSchema = c.UpdateFn(s, exist, c.collection) collection, upd, setSchema = c.UpdateFn(s, exist, c.collection)
if upd { if upd {
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/environments" "git.perx.ru/perxis/perxis-go/pkg/environments"
envmocks "git.perx.ru/perxis/perxis-go/pkg/environments/mocks" envmocks "git.perx.ru/perxis/perxis-go/pkg/environments/mocks"
"git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/extension"
"git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/schema"
"git.perx.ru/perxis/perxis-go/pkg/schema/field" "git.perx.ru/perxis/perxis-go/pkg/schema/field"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
...@@ -22,7 +23,6 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -22,7 +23,6 @@ func TestSetup_InstallCollections(t *testing.T) {
collections []*collections.Collection collections []*collections.Collection
collectionsCall func(svc *mockscollections.Collections) collectionsCall func(svc *mockscollections.Collections)
envsCall func(svc *envmocks.Environments) envsCall func(svc *envmocks.Environments)
co CollectionsOption
force bool force bool
wantErr func(t *testing.T, err error) wantErr func(t *testing.T, err error)
}{ }{
...@@ -95,10 +95,10 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -95,10 +95,10 @@ func TestSetup_InstallCollections(t *testing.T) {
}, },
{ {
name: "Update extension collection with metadata", name: "Update extension collection with metadata",
collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata("extension", "test-extension")}}, collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata(extension.ExtensionMetadataKey, "test-extension")}},
collectionsCall: func(svc *mockscollections.Collections) { 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("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata(extension.ExtensionMetadataKey, "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("Update", mock.Anything, &collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata(extension.ExtensionMetadataKey, "test-extension")}).Return(nil).Once()
svc.On("SetSchema", mock.Anything, "sp", "env", "1", schema.New("name", field.String())).Return(nil).Once() svc.On("SetSchema", mock.Anything, "sp", "env", "1", schema.New("name", field.String())).Return(nil).Once()
}, },
envsCall: func(svc *envmocks.Environments) { envsCall: func(svc *envmocks.Environments) {
...@@ -107,43 +107,14 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -107,43 +107,14 @@ 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"),
},
{
name: "Fail to update collection with the same id",
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("surname", field.String())}, nil).Once()
},
wantErr: func(t *testing.T, err error) {
assert.Error(t, err)
},
co: SetSchemaMetadata("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("extension", "test-extension"),
force: true,
}, },
{ {
name: "Update exist view collection with the same id", name: "Update exist view collection with the same id",
collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata("extension", "test-extension")}}, collections: []*collections.Collection{{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata(extension.ExtensionMetadataKey, "test-extension")}},
collectionsCall: func(svc *mockscollections.Collections) { collectionsCall: func(svc *mockscollections.Collections) {
svc.On("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", View: &collections.View{SpaceID: "sp2", EnvID: environments.DefaultEnvironment, CollectionID: "2"}}, nil).Once() svc.On("Get", mock.Anything, "sp", "env", "1").Return(&collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", View: &collections.View{SpaceID: "sp2", EnvID: environments.DefaultEnvironment, CollectionID: "2"}}, 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("Update", mock.Anything, &collections.Collection{ID: "1", SpaceID: "sp", EnvID: "env", Schema: schema.New("name", field.String()).WithMetadata(extension.ExtensionMetadataKey, "test-extension")}).Return(nil).Once()
svc.On("SetSchema", mock.Anything, "sp", "env", "1", 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()).WithMetadata(extension.ExtensionMetadataKey, "test-extension")).Return(nil).Once()
}, },
envsCall: func(svc *envmocks.Environments) { envsCall: func(svc *envmocks.Environments) {
svc.On("Migrate", mock.Anything, "sp", "env", &environments.MigrateOptions{Wait: true}).Return(nil).Once() svc.On("Migrate", mock.Anything, "sp", "env", &environments.MigrateOptions{Wait: true}).Return(nil).Once()
...@@ -151,7 +122,6 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -151,7 +122,6 @@ 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"),
}, },
{ {
name: "Update view collection with the same id to new view collection", name: "Update view collection with the same id to new view collection",
...@@ -166,7 +136,6 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -166,7 +136,6 @@ 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"),
}, },
} }
...@@ -183,11 +152,7 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -183,11 +152,7 @@ func TestSetup_InstallCollections(t *testing.T) {
s := NewSetup(&content.Content{Collections: c, Environments: e}, "sp", "env", nil) s := NewSetup(&content.Content{Collections: c, Environments: e}, "sp", "env", nil)
s.force = tt.force s.force = tt.force
if tt.co != nil {
s.AddCollections(tt.collections, tt.co)
} else {
s.AddCollections(tt.collections) s.AddCollections(tt.collections)
}
tt.wantErr(t, s.InstallCollections(context.Background())) tt.wantErr(t, s.InstallCollections(context.Background()))
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment