Skip to content

Commit

Permalink
target tests
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
  • Loading branch information
Frank Jogeleit committed Apr 28, 2024
1 parent d67fc61 commit 4ae4ec8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pkg/target/kinesis/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ func (c *client) Send(result v1alpha2.PolicyReportResult) {
t := time.Unix(result.Timestamp.Seconds, int64(result.Timestamp.Nanos))
key := fmt.Sprintf("%s-%s-%s", result.Policy, result.ID, t.Format(time.RFC3339Nano))

err := c.kinesis.Upload(body, key)
if err != nil {
if err := c.kinesis.Upload(body, key); err != nil {
zap.L().Error("kinesis upload error", zap.String("name", c.Name()), zap.Error(err))
return
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/target/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (c *client) Send(result v1alpha2.PolicyReportResult) {
t := time.Unix(result.Timestamp.Seconds, int64(result.Timestamp.Nanos))
key := fmt.Sprintf("%s/%s/%s-%s-%s.json", c.prefix, t.Format("2006-01-02"), result.Policy, result.ID, t.Format(time.RFC3339Nano))

err := c.s3.Upload(body, key)
if err != nil {
if err := c.s3.Upload(body, key); err != nil {
zap.L().Error(c.Name()+": S3 Upload error", zap.Error(err))
return
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/target/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ func Test_UITarget(t *testing.T) {
t.Errorf("Unexpected Name %s", client.Name())
}
})
t.Run("Request Error", func(t *testing.T) {
callback := func(req *http.Request) {
t.Fail()
}

client := ui.NewClient(ui.Options{
ClientOptions: target.ClientOptions{
Name: "UI",
},
Host: "\\localhost:8080",
HTTPClient: testClient{callback, 200},
})
client.Send(fixtures.CompleteTargetSendResult)
})
}
16 changes: 16 additions & 0 deletions pkg/target/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ func Test_UITarget(t *testing.T) {
t.Errorf("Unexpected Name %s", client.Name())
}
})
t.Run("Request Error", func(t *testing.T) {
callback := func(req *http.Request) error {
t.Fail()

return nil
}

client := webhook.NewClient(webhook.Options{
ClientOptions: target.ClientOptions{
Name: "UI",
},
Host: "\\localhost:8080",
HTTPClient: testClient{callback, 200},
})
client.Send(fixtures.CompleteTargetSendResult)
})
}

0 comments on commit 4ae4ec8

Please sign in to comment.