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

Merge branch 'master' into feature/PRXS-1380-AddMetadataToSchema

# Conflicts:
#	pkg/setup/collection_test.go
parents 21c8e2d7 fc5fc35e
No related branches found
No related tags found
No related merge requests found
...@@ -21,8 +21,6 @@ const ( ...@@ -21,8 +21,6 @@ const (
StateInstalled = pb.SpaceExtensions_INSTALLED StateInstalled = pb.SpaceExtensions_INSTALLED
StateInProgress = pb.SpaceExtensions_IN_PROGRESS StateInProgress = pb.SpaceExtensions_IN_PROGRESS
StateFail = pb.SpaceExtensions_FAIL StateFail = pb.SpaceExtensions_FAIL
ExtensionMetadataKey = "extension"
) )
type ( type (
......
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
type Schema struct { type Schema struct {
field.Field field.Field
Loaded bool `json:"loaded"` Loaded bool `json:"loaded"`
Metadata map[string]string `json:"metadata"`
} }
func New(kv ...interface{}) *Schema { func New(kv ...interface{}) *Schema {
...@@ -36,7 +35,6 @@ func (s *Schema) Clone(reset bool) *Schema { ...@@ -36,7 +35,6 @@ func (s *Schema) Clone(reset bool) *Schema {
return &Schema{ return &Schema{
Field: *s.Field.Clone(reset), Field: *s.Field.Clone(reset),
Loaded: s.Loaded, Loaded: s.Loaded,
Metadata: s.Metadata,
} }
} }
...@@ -45,21 +43,6 @@ func (s Schema) WithIncludes(includes ...interface{}) *Schema { ...@@ -45,21 +43,6 @@ func (s Schema) WithIncludes(includes ...interface{}) *Schema {
return &s return &s
} }
func (s *Schema) WithMetadata(kv ...string) *Schema {
if s.Metadata == nil {
s.Metadata = make(map[string]string)
}
for i := 0; i < len(kv); i += 2 {
s.Metadata[kv[i]] = kv[i+1]
}
return s
}
func (s Schema) SetMetadata(md map[string]string) *Schema {
s.Metadata = md
return &s
}
func (s *Schema) Load(ctx context.Context) error { func (s *Schema) Load(ctx context.Context) error {
if s.Loaded { if s.Loaded {
return nil return nil
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
) )
type jsonSchema struct { type jsonSchema struct {
//Field json.RawMessage `json:"field,inline"`
Loaded bool `json:"loaded"` Loaded bool `json:"loaded"`
Metadata map[string]string `json:"metadata"`
} }
func (s *Schema) UnmarshalJSON(b []byte) error { func (s *Schema) UnmarshalJSON(b []byte) error {
...@@ -17,12 +17,20 @@ func (s *Schema) UnmarshalJSON(b []byte) error { ...@@ -17,12 +17,20 @@ func (s *Schema) UnmarshalJSON(b []byte) error {
return errors.Wrapf(err, "error unmarshal json into field") return errors.Wrapf(err, "error unmarshal json into field")
} }
s.Loaded = j.Loaded s.Loaded = j.Loaded
s.Metadata = j.Metadata
if err := s.Field.UnmarshalJSON(b); err != nil { if err := s.Field.UnmarshalJSON(b); err != nil {
return err return err
} }
//if len(j.Field) > 0 {
// if err := s.Field.UnmarshalJSON(j.Field); err != nil {
// return err
// }
// //if err := jsoniter.Unmarshal(j.Field, &s.Field); err != nil {
// // return err
// //}
//}
return nil return nil
} }
...@@ -34,8 +42,8 @@ func (s *Schema) MarshalJSON() ([]byte, error) { ...@@ -34,8 +42,8 @@ func (s *Schema) MarshalJSON() ([]byte, error) {
} }
jsonSch, err := jsoniter.Marshal(jsonSchema{ jsonSch, err := jsoniter.Marshal(jsonSchema{
//Field: b,
Loaded: s.Loaded, Loaded: s.Loaded,
Metadata: s.Metadata,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -110,9 +110,6 @@ func TestSchema_JSON(t *testing.T) { ...@@ -110,9 +110,6 @@ func TestSchema_JSON(t *testing.T) {
"evaluatedField", field.String(modify.Value("stringField2 + '_' ")), "evaluatedField", field.String(modify.Value("stringField2 + '_' ")),
) )
sch.Loaded = true sch.Loaded = true
sch.Metadata = map[string]string{
"extension": "test-extension",
}
b, err := json.MarshalIndent(sch, "", " ") b, err := json.MarshalIndent(sch, "", " ")
require.NoError(t, err) require.NoError(t, err)
......
...@@ -15,7 +15,6 @@ var ( ...@@ -15,7 +15,6 @@ 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)
...@@ -24,7 +23,6 @@ type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool ...@@ -24,7 +23,6 @@ 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
UpdateFn UpdateCollectionFn UpdateFn UpdateCollectionFn
DeleteFn DeleteCollectionFn DeleteFn DeleteCollectionFn
} }
...@@ -127,7 +125,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -127,7 +125,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
collection.SpaceID, collection.EnvID = s.SpaceID, s.EnvironmentID collection.SpaceID, collection.EnvID = s.SpaceID, s.EnvironmentID
var exist *collections.Collection var exist *collections.Collection
// isForce - не удалять коллекцию, если она уже существует
exist, err = s.content.Collections.Get(ctx, collection.SpaceID, collection.EnvID, collection.ID) exist, err = s.content.Collections.Get(ctx, collection.SpaceID, collection.EnvID, collection.ID)
if err != nil && !strings.Contains(err.Error(), collections.ErrNotFound.Error()) { if err != nil && !strings.Contains(err.Error(), collections.ErrNotFound.Error()) {
return false, err return false, err
...@@ -135,7 +133,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS ...@@ -135,7 +133,7 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
if exist == nil { if exist == nil {
setSchema = !collection.IsView() setSchema = !collection.IsView()
_, err = s.content.Collections.Create(ctx, collection) exist, err = s.content.Collections.Create(ctx, collection)
if err != nil { if err != nil {
return false, err return false, err
} }
......
...@@ -23,7 +23,6 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -23,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)
force bool
wantErr func(t *testing.T, err error) wantErr func(t *testing.T, err error)
}{ }{
{ {
...@@ -151,7 +150,6 @@ func TestSetup_InstallCollections(t *testing.T) { ...@@ -151,7 +150,6 @@ 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.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