Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 committed Jan 25, 2025
1 parent 468a536 commit 4f2d8f0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 0 additions & 2 deletions pkg/plugins/trivy/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6659,7 +6659,6 @@ var (
NoneCount: 0,
UnknownCount: 0,
},
Vulnerabilities: []v1alpha1.Vulnerability{},
}

emptyExposedSecretReport = v1alpha1.ExposedSecretReportData{
Expand All @@ -6682,7 +6681,6 @@ var (
MediumCount: 0,
LowCount: 0,
},
Secrets: []v1alpha1.ExposedSecret{},
}
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func createDataFS(dataPaths []string, k8sVersion string) (fs.FS, []string, error
if err := fsys.MkdirAll("system", 0700); err != nil {
return nil, nil, err
}
data := []byte(fmt.Sprintf(`{"k8s": {"version": "%q"}}`, k8sVersion))
data := []byte(fmt.Sprintf(`{"k8s": {"version": %q}}`, k8sVersion))
if err := fsys.WriteVirtualFile("system/k8s-version.json", data, 0600); err != nil {
return nil, nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/trivyoperator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,10 +1130,9 @@ func TestConfigData_GetExcludeImages(t *testing.T) {
expected: []string{"docker.io/*"},
},
{
name: "no pattern",
key: "scanJob.excludeImages",
value: "",
expected: []string{},
name: "no pattern",
key: "scanJob.excludeImages",
value: "",
},
}
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/dateutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ func TestTTLIsExpired(t *testing.T) {
creationTime := time.Now()
then := creationTime.Add(time.Duration(-10) * time.Minute)
ttlExpired, duration := IsTTLExpired(ttlReportTime, then, ext.NewSystemClock())
assert.LessOrEqual(t, duration, 0)
assert.True(t, duration <= 0) // nolint: testifylint
assert.True(t, ttlExpired)
}
2 changes: 1 addition & 1 deletion pkg/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMapResources(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := MapKinds(tt.kinds)
assert.Len(t, tt.want, len(got))
assert.Equal(t, tt.want, len(got)) // nolint: testifylint
})
}
}
6 changes: 5 additions & 1 deletion pkg/webhook/webhookreporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func sendReport[T any](reports T, endpoint string, timeout time.Duration, header
req.Header = headerValues

resp, err := hc.Do(req)
defer func() { _ = resp.Body.Close() }()
defer func() {
if resp != nil {
_ = resp.Body.Close()
}
}()
if err != nil {
return fmt.Errorf("failed to send reports to endpoint: %w", err)
}
Expand Down

0 comments on commit 4f2d8f0

Please sign in to comment.