Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab Agent for Kubernetes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
cluster-integration
GitLab Agent for Kubernetes
Commits
aa712f5b
Commit
aa712f5b
authored
3 years ago
by
Mikhail Mazurskiy
Browse files
Options
Downloads
Plain Diff
Merge branch 'ash2k/embed-jsonbox' into 'master'
Embed JsonBox into field See merge request
!479
parents
07dcce60
a7f27a25
No related branches found
No related tags found
1 merge request
!479
Embed JsonBox into field
Pipeline
#355626408
passed
3 years ago
Stage: test
Stage: scan
Stage: push_image
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/module/cilium_alert/agent/worker.go
+2
-2
2 additions, 2 deletions
internal/module/cilium_alert/agent/worker.go
internal/tool/prototool/jsonbox_test.go
+75
-17
75 additions, 17 deletions
internal/tool/prototool/jsonbox_test.go
with
77 additions
and
19 deletions
internal/module/cilium_alert/agent/worker.go
+
2
−
2
View file @
aa712f5b
...
...
@@ -157,7 +157,7 @@ func (w *worker) processFlow(ctx context.Context, flw *flow.Flow, informer cache
func
(
w
*
worker
)
sendAlert
(
ctx
context
.
Context
,
fl
*
flow
.
Flow
,
cnp
*
v2
.
CiliumNetworkPolicy
)
(
retErr
error
)
{
mbdy
,
err
:=
json
.
Marshal
(
payload
{
Alert
:
alert
{
Flow
:
&
prototool
.
JsonBox
{
Message
:
fl
},
Flow
:
prototool
.
JsonBox
{
Message
:
fl
},
CiliumNetworkPolicy
:
cnp
,
},
})
...
...
@@ -187,6 +187,6 @@ type payload struct {
}
type
alert
struct
{
Flow
*
prototool
.
JsonBox
`json:"flow"`
Flow
prototool
.
JsonBox
`json:"flow"`
CiliumNetworkPolicy
*
v2
.
CiliumNetworkPolicy
`json:"ciliumNetworkPolicy"`
}
This diff is collapsed.
Click to expand it.
internal/tool/prototool/jsonbox_test.go
+
75
−
17
View file @
aa712f5b
...
...
@@ -2,6 +2,7 @@ package prototool
import
(
"encoding/json"
"strconv"
"testing"
"github.com/google/go-cmp/cmp"
...
...
@@ -17,31 +18,88 @@ var (
// Test round trip using stdlib json package.
func
TestJsonBox_RoundTrip
(
t
*
testing
.
T
)
{
source
:=
&
JsonBox
{
Message
:
&
HttpRequest
{
Method
:
"POST"
,
Header
:
map
[
string
]
*
Values
{
"Req-Header"
:
{
Value
:
[]
string
{
"x1"
,
"x2"
},
val
:=
&
HttpRequest
{
Method
:
"POST"
,
Header
:
map
[
string
]
*
Values
{
"Req-Header"
:
{
Value
:
[]
string
{
"x1"
,
"x2"
},
},
},
UrlPath
:
"adsad"
,
Query
:
map
[
string
]
*
Values
{
"asdsad"
:
{
Value
:
[]
string
{
"asdasds"
},
},
},
}
tests
:=
[]
struct
{
input
interface
{}
output
interface
{}
expected
interface
{}
// input is used if not set
}{
{
input
:
&
JsonBox
{
Message
:
val
,
},
output
:
&
JsonBox
{
Message
:
&
HttpRequest
{},
},
},
{
input
:
&
embeddedBox
{
A
:
JsonBox
{
Message
:
val
,
},
B
:
&
JsonBox
{
Message
:
val
,
},
},
UrlPath
:
"adsad"
,
Query
:
map
[
string
]
*
Values
{
"asdsad"
:
{
Value
:
[]
string
{
"asdasds"
},
output
:
&
embeddedBox
{
A
:
JsonBox
{
Message
:
&
HttpRequest
{},
},
B
:
&
JsonBox
{
Message
:
&
HttpRequest
{},
},
},
},
{
input
:
&
embeddedBox
{},
output
:
&
embeddedBox
{
A
:
JsonBox
{
Message
:
&
HttpRequest
{},
},
B
:
&
JsonBox
{
Message
:
&
HttpRequest
{},
},
},
expected
:
&
embeddedBox
{
A
:
JsonBox
{
Message
:
&
HttpRequest
{},
},
},
},
}
for
i
,
tc
:=
range
tests
{
t
.
Run
(
strconv
.
Itoa
(
i
),
func
(
t
*
testing
.
T
)
{
data
,
err
:=
json
.
Marshal
(
tc
.
input
)
require
.
NoError
(
t
,
err
)
data
,
err
:
=
json
.
M
arshal
(
source
)
require
.
NoError
(
t
,
err
)
err
=
json
.
Unm
arshal
(
data
,
tc
.
output
)
require
.
NoError
(
t
,
err
)
actual
:=
&
JsonBox
{
Message
:
&
HttpRequest
{},
var
expected
interface
{}
if
tc
.
expected
!=
nil
{
expected
=
tc
.
expected
}
else
{
expected
=
tc
.
input
}
assert
.
Empty
(
t
,
cmp
.
Diff
(
expected
,
tc
.
output
,
protocmp
.
Transform
()))
})
}
err
=
json
.
Unmarshal
(
data
,
actual
)
require
.
NoError
(
t
,
err
)
}
assert
.
Empty
(
t
,
cmp
.
Diff
(
source
.
Message
,
actual
.
Message
,
protocmp
.
Transform
()))
type
embeddedBox
struct
{
A
JsonBox
B
*
JsonBox
}
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