Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
policy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
policy
Commits
add76df4
Commit
add76df4
authored
1 year ago
by
Valentin Yordanov
Browse files
Options
Downloads
Patches
Plain Diff
Fix linters
parent
41cb10c3
No related branches found
No related tags found
1 merge request
!44
Creating listing policies endpoint
Pipeline
#66767
passed
1 year ago
Stage: test
Stage: build
Stage: manifest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/service/policy/policydata/refresher_test.go
+8
-8
8 additions, 8 deletions
internal/service/policy/policydata/refresher_test.go
internal/storage/storage.go
+2
-2
2 additions, 2 deletions
internal/storage/storage.go
with
10 additions
and
10 deletions
internal/service/policy/policydata/refresher_test.go
+
8
−
8
View file @
add76df4
...
@@ -34,7 +34,7 @@ func Test_Execute(t *testing.T) {
...
@@ -34,7 +34,7 @@ func Test_Execute(t *testing.T) {
// test input
// test input
name
string
name
string
statusCode
int
statusCode
int
policy
storage
.
Policy
policy
*
storage
.
Policy
storage
policydata
.
Storage
storage
policydata
.
Storage
// expected result
// expected result
logCnt
int
logCnt
int
...
@@ -42,7 +42,7 @@ func Test_Execute(t *testing.T) {
...
@@ -42,7 +42,7 @@ func Test_Execute(t *testing.T) {
}{
}{
{
{
name
:
"invalid data configuration"
,
name
:
"invalid data configuration"
,
policy
:
storage
.
Policy
{
DataConfig
:
"<invalid data configuration>"
},
policy
:
&
storage
.
Policy
{
DataConfig
:
"<invalid data configuration>"
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
nil
return
nil
...
@@ -53,7 +53,7 @@ func Test_Execute(t *testing.T) {
...
@@ -53,7 +53,7 @@ func Test_Execute(t *testing.T) {
},
},
{
{
name
:
"data configuration is missing required fields"
,
name
:
"data configuration is missing required fields"
,
policy
:
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com"}`
},
policy
:
&
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com"}`
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
nil
return
nil
...
@@ -64,7 +64,7 @@ func Test_Execute(t *testing.T) {
...
@@ -64,7 +64,7 @@ func Test_Execute(t *testing.T) {
},
},
{
{
name
:
"error making an http request"
,
name
:
"error making an http request"
,
policy
:
storage
.
Policy
{
DataConfig
:
`{"url": "htt//example.com", "method": "GET", "period": "1h"}`
},
policy
:
&
storage
.
Policy
{
DataConfig
:
`{"url": "htt//example.com", "method": "GET", "period": "1h"}`
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
nil
return
nil
...
@@ -76,7 +76,7 @@ func Test_Execute(t *testing.T) {
...
@@ -76,7 +76,7 @@ func Test_Execute(t *testing.T) {
{
{
name
:
"unexpected response code"
,
name
:
"unexpected response code"
,
statusCode
:
500
,
statusCode
:
500
,
policy
:
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
policy
:
&
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
nil
return
nil
...
@@ -87,7 +87,7 @@ func Test_Execute(t *testing.T) {
...
@@ -87,7 +87,7 @@ func Test_Execute(t *testing.T) {
},
},
{
{
name
:
"error updating data after successful refresh request"
,
name
:
"error updating data after successful refresh request"
,
policy
:
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
policy
:
&
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
errors
.
New
(
"storage error"
)
return
errors
.
New
(
"storage error"
)
...
@@ -98,7 +98,7 @@ func Test_Execute(t *testing.T) {
...
@@ -98,7 +98,7 @@ func Test_Execute(t *testing.T) {
},
},
{
{
name
:
"data refresh is successfully executed"
,
name
:
"data refresh is successfully executed"
,
policy
:
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
policy
:
&
storage
.
Policy
{
DataConfig
:
`{"url": "https://example.com", "method": "GET", "period": "1h"}`
},
storage
:
&
policydatafakes
.
FakeStorage
{
storage
:
&
policydatafakes
.
FakeStorage
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
UpdateNextRefreshTimeStub
:
func
(
ctx
context
.
Context
,
policy
*
storage
.
Policy
,
t
time
.
Time
)
error
{
return
nil
return
nil
...
@@ -121,7 +121,7 @@ func Test_Execute(t *testing.T) {
...
@@ -121,7 +121,7 @@ func Test_Execute(t *testing.T) {
})
})
}
}
refresher
:=
policydata
.
NewRefresher
(
test
.
storage
,
time
.
Duration
(
0
),
httpClient
,
logger
)
refresher
:=
policydata
.
NewRefresher
(
test
.
storage
,
time
.
Duration
(
0
),
httpClient
,
logger
)
refresher
.
Execute
(
context
.
Background
(),
(
*
storage
.
Policy
)(
&
test
.
policy
)
)
refresher
.
Execute
(
context
.
Background
(),
test
.
policy
)
assert
.
Equal
(
t
,
test
.
logCnt
,
observedLogs
.
Len
())
assert
.
Equal
(
t
,
test
.
logCnt
,
observedLogs
.
Len
())
if
observedLogs
.
Len
()
>
0
{
if
observedLogs
.
Len
()
>
0
{
...
...
This diff is collapsed.
Click to expand it.
internal/storage/storage.go
+
2
−
2
View file @
add76df4
...
@@ -165,9 +165,9 @@ func (s *Storage) GetRefreshPolicies(ctx context.Context) ([]*Policy, error) {
...
@@ -165,9 +165,9 @@ func (s *Storage) GetRefreshPolicies(ctx context.Context) ([]*Policy, error) {
// PostponeRefresh adds a refreshPostponePeriod Duration to each policy's
// PostponeRefresh adds a refreshPostponePeriod Duration to each policy's
// nextDataRefreshTimeField in order to prevent concurrent data refresh
// nextDataRefreshTimeField in order to prevent concurrent data refresh
func
(
s
*
Storage
)
PostponeRefresh
(
ctx
context
.
Context
,
policies
[]
*
Policy
)
error
{
func
(
s
*
Storage
)
PostponeRefresh
(
ctx
context
.
Context
,
policies
[]
*
Policy
)
error
{
var
ids
[]
*
primitive
.
ObjectID
var
ids
[]
primitive
.
ObjectID
for
_
,
p
:=
range
policies
{
for
_
,
p
:=
range
policies
{
ids
=
append
(
ids
,
(
*
primitive
.
ObjectID
)(
&
p
.
ID
)
)
ids
=
append
(
ids
,
p
.
ID
)
}
}
filter
:=
bson
.
M
{
"_id"
:
bson
.
M
{
"$in"
:
ids
}}
filter
:=
bson
.
M
{
"_id"
:
bson
.
M
{
"$in"
:
ids
}}
...
...
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