Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
6ad38a75
Commit
6ad38a75
authored
2 years ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
правки по ПР:
- добавлено поле metadata в CollectionConfig - добавлена опция SetSchemaMetadata
parent
b83b003c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/setup/collection.go
+12
-3
12 additions, 3 deletions
pkg/setup/collection.go
pkg/setup/collection_test.go
+8
-1
8 additions, 1 deletion
pkg/setup/collection_test.go
with
20 additions
and
4 deletions
pkg/setup/collection.go
+
12
−
3
View file @
6ad38a75
...
@@ -23,6 +23,7 @@ type DeleteCollectionFn func(s *Setup, col *collections.Collection) bool
...
@@ -23,6 +23,7 @@ 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
}
}
...
@@ -80,6 +81,12 @@ func UpdateExistingCollection() CollectionsOption {
...
@@ -80,6 +81,12 @@ func UpdateExistingCollection() CollectionsOption {
}
}
}
}
func
SetSchemaMetadata
(
md
map
[
string
]
string
)
CollectionsOption
{
return
func
(
c
*
CollectionConfig
)
{
c
.
metadata
=
md
}
}
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
...
@@ -164,11 +171,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
...
@@ -164,11 +171,13 @@ func (s *Setup) InstallCollection(ctx context.Context, c CollectionConfig) (setS
}
}
func
(
s
*
Setup
)
checkSchemaMetadata
(
collection
*
collections
.
Collection
,
exist
*
collections
.
Collection
)
error
{
func
(
s
*
Setup
)
checkSchemaMetadata
(
collection
*
collections
.
Collection
,
exist
*
collections
.
Collection
)
error
{
if
collection
.
Schema
.
Metadata
!=
nil
{
if
_
,
ok
:=
collection
.
Schema
.
Metadata
[
"extension"
];
ok
{
if
_
,
ok
:=
collection
.
Schema
.
Metadata
[
"extension"
];
ok
{
if
_
,
ok
:=
exist
.
Schema
.
Metadata
[
"extension"
];
!
ok
&&
!
s
.
IsForce
()
{
if
_
,
ok
:=
exist
.
Schema
.
Metadata
[
"extension"
];
!
ok
&&
!
s
.
IsForce
()
{
return
errors
.
WithHint
(
errors
.
New
(
"fail to update collection"
),
"collection has the same id as extension's collection, change yours collection id"
)
return
errors
.
WithHint
(
errors
.
New
(
"fail to update collection"
),
"collection has the same id as extension's collection, change yours collection id"
)
}
}
}
}
}
return
nil
return
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/setup/collection_test.go
+
8
−
1
View file @
6ad38a75
...
@@ -22,6 +22,7 @@ func TestSetup_InstallCollections(t *testing.T) {
...
@@ -22,6 +22,7 @@ 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
wantErr
func
(
t
*
testing
.
T
,
err
error
)
wantErr
func
(
t
*
testing
.
T
,
err
error
)
}{
}{
{
{
...
@@ -105,6 +106,7 @@ func TestSetup_InstallCollections(t *testing.T) {
...
@@ -105,6 +106,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"
}),
},
},
{
{
name
:
"Fail to update collection with the same id"
,
name
:
"Fail to update collection with the same id"
,
...
@@ -115,6 +117,7 @@ func TestSetup_InstallCollections(t *testing.T) {
...
@@ -115,6 +117,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"
}),
},
},
}
}
...
@@ -130,7 +133,11 @@ func TestSetup_InstallCollections(t *testing.T) {
...
@@ -130,7 +133,11 @@ 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
)
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
()))
})
})
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment