Skip to content
Snippets Groups Projects
Commit c84ddaa6 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'fix/PRXS-1762-SetupUpdateChangedSchemas' into 'master'

Исправлена ошибка, при которой при заданной в Setup опции перезаписи коллекций они не обновлялись при изменении схемы

See merge request perxis/perxis-go!121
parents 7378cc86 51fa2b09
No related branches found
No related tags found
No related merge requests found
...@@ -61,9 +61,9 @@ func OverwriteCollection() CollectionsOption { ...@@ -61,9 +61,9 @@ func OverwriteCollection() CollectionsOption {
return func(c *CollectionConfig) { return func(c *CollectionConfig) {
c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool, error) { c.UpdateFn = func(s *Setup, old, new *collections.Collection) (*collections.Collection, bool, bool, error) {
update := new.Name != old.Name || new.IsSingle() != old.IsSingle() || new.IsSystem() != old.IsSystem() || update := new.Name != old.Name || new.IsSingle() != old.IsSingle() || new.IsSystem() != old.IsSystem() ||
new.IsNoData() != old.IsNoData() || new.Hidden != old.Hidden || new.IsView() != old.IsView() || !data.ElementsMatch(old.Tags, new.Tags) new.IsNoData() != old.IsNoData() || new.Hidden != old.Hidden || !new.View.Equal(old.View) || !data.ElementsMatch(old.Tags, new.Tags)
return new, update, old.Schema.Equal(new.Schema), nil return new, update, !old.Schema.Equal(new.Schema), nil
} }
} }
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"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"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
) )
func TestSetup_InstallCollections(t *testing.T) { func TestSetup_InstallCollections(t *testing.T) {
...@@ -156,3 +157,52 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -156,3 +157,52 @@ func TestSetup_InstallCollections(t *testing.T) {
}) })
} }
} }
func TestOverwriteCollection(t *testing.T) {
tests := []struct {
name string
old, new *collections.Collection
wantUpdate bool
wantSetSchema bool
wantErr bool
}{
{
name: "Equal collections should not be updated",
old: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Schema: schema.New("a", field.String())},
new: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Schema: schema.New("a", field.String())},
wantUpdate: false,
wantSetSchema: false,
},
{
name: "For collections with different schemas and equal other params schemas should be set",
old: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Name: "Coll", Schema: schema.New("a", field.String())},
new: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Name: "Coll", Schema: schema.New("b", field.String())},
wantUpdate: false,
wantSetSchema: true,
},
{
name: "Collections with different names should be updated",
old: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Name: "Coll1", Schema: schema.New("a", field.String())},
new: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", Name: "Coll2", Schema: schema.New("a", field.String())},
wantUpdate: true,
wantSetSchema: false,
},
{
name: "Collections with different view params should be updated",
old: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", View: &collections.View{SpaceID: "sp1", EnvID: "env1", CollectionID: "coll1"}},
new: &collections.Collection{ID: "coll", SpaceID: "sp", EnvID: "env", View: &collections.View{SpaceID: "sp2", EnvID: "env2", CollectionID: "coll2"}},
wantUpdate: true,
wantSetSchema: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := new(CollectionConfig)
OverwriteCollection()(c)
_, update, setSchema, err := c.UpdateFn(new(Setup), tt.old, tt.new)
require.NoError(t, err)
assert.Equal(t, tt.wantUpdate, update)
assert.Equal(t, tt.wantSetSchema, setSchema)
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment