Skip to content

Commit

Permalink
change send result tests to account for new sending logic
Browse files Browse the repository at this point in the history
Signed-off-by: aerosouund <[email protected]>
  • Loading branch information
aerosouund committed Feb 20, 2025
1 parent 21fcc53 commit ce57e0b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/listener/scope_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package listener_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/kyverno/policy-reporter/pkg/cache"
"github.com/kyverno/policy-reporter/pkg/crd/api/policyreport/v1alpha2"
"github.com/kyverno/policy-reporter/pkg/fixtures"
"github.com/kyverno/policy-reporter/pkg/listener"
Expand All @@ -14,20 +16,30 @@ import (
func Test_ScopeResultsListener(t *testing.T) {
t.Run("Send Results", func(t *testing.T) {
c := &client{validated: true, batchSend: true}
resultCache := cache.NewInMermoryCache(time.Hour, time.Hour)
c.SetCache(resultCache)

slistener := listener.NewSendScopeResultsListener(target.NewCollection(&target.Target{Client: c}))
slistener(preport1, []v1alpha2.PolicyReportResult{fixtures.FailResult})

assert.True(t, c.Called, "Expected Send to be called")
})
t.Run("Don't Send Result when validation fails", func(t *testing.T) {
c := &client{validated: false, batchSend: true}
resultCache := cache.NewInMermoryCache(time.Hour, time.Hour)
c.SetCache(resultCache)

slistener := listener.NewSendScopeResultsListener(target.NewCollection(&target.Target{Client: c}))
slistener(preport1, []v1alpha2.PolicyReportResult{fixtures.FailResult})

assert.False(t, c.Called, "Expected Send not to be called")
})
t.Run("Don't Send pre existing Result when skipExistingOnStartup is true", func(t *testing.T) {
c := &client{skipExistingOnStartup: true, batchSend: true}
resultCache := cache.NewInMermoryCache(time.Hour, time.Hour)
resultCache.AddReport(preport1)
c.SetCache(resultCache)

slistener := listener.NewSendScopeResultsListener(target.NewCollection(&target.Target{Client: c}))
slistener(preport1, []v1alpha2.PolicyReportResult{fixtures.FailResult})

Expand Down

0 comments on commit ce57e0b

Please sign in to comment.