Skip to content

Commit 770c9ad

Browse files
authored
chore: add unit tests (#523)
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
1 parent a8e1ab0 commit 770c9ad

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

.release-notes/main.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Release notes for `TODO`.
3535
- Fixed `check` set to `null` in kuttl migration command
3636
- Fixed a manifest discovery issue where manifests could be loaded in the wrong order
3737
- Fixed a manifest discovery issue where error manifests where not discovered correctly
38+
- Fixed controller-runtime logger not initialised
3839

3940
## :books: Docs :books:
4041

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21.1
55
require (
66
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2
77
github.com/fatih/color v1.16.0
8+
github.com/go-logr/logr v1.2.4
89
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
910
github.com/jmespath-community/go-jmespath v1.1.2-0.20231004164315-78945398586a
1011
github.com/kudobuilder/kuttl v0.15.0
@@ -43,7 +44,6 @@ require (
4344
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
4445
github.com/felixge/httpsnoop v1.0.3 // indirect
4546
github.com/fsnotify/fsnotify v1.6.0 // indirect
46-
github.com/go-logr/logr v1.2.4 // indirect
4747
github.com/go-logr/stdr v1.2.2 // indirect
4848
github.com/go-openapi/jsonpointer v0.20.0 // indirect
4949
github.com/go-openapi/jsonreference v0.20.2 // indirect

main.go

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package main
33
import (
44
"os"
55

6+
"github.com/go-logr/logr"
67
"github.com/kyverno/chainsaw/pkg/commands"
8+
"sigs.k8s.io/controller-runtime/pkg/log"
79
)
810

911
func main() {
12+
log.SetLogger(logr.Discard())
1013
root := commands.RootCommand()
1114
if err := root.Execute(); err != nil {
1215
os.Exit(1)

pkg/runner/operations/command/command_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ func Test_operationCommand(t *testing.T) {
6868
basePath: "..",
6969
namespace: "test-namespace",
7070
wantErr: false,
71+
}, {
72+
name: "with bad check",
73+
command: v1alpha1.Command{
74+
Entrypoint: "foo",
75+
Args: []string{"operation.go"},
76+
SkipLogOutput: true,
77+
Check: &v1alpha1.Check{
78+
Value: map[string]interface{}{
79+
"(foo('bar'))": true,
80+
},
81+
},
82+
},
83+
basePath: "..",
84+
namespace: "test-namespace",
85+
wantErr: true,
86+
}, {
87+
name: "with bad check",
88+
command: v1alpha1.Command{
89+
Entrypoint: "cat",
90+
Args: []string{"operation.go"},
91+
SkipLogOutput: true,
92+
Check: &v1alpha1.Check{
93+
Value: map[string]interface{}{
94+
"(foo('bar'))": true,
95+
},
96+
},
97+
},
98+
basePath: "..",
99+
namespace: "test-namespace",
100+
wantErr: true,
71101
}}
72102
for _, tt := range tests {
73103
t.Run(tt.name, func(t *testing.T) {

pkg/runner/operations/script/script_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ func Test_operationScript(t *testing.T) {
6464
basePath: "..",
6565
namespace: "test-namespace",
6666
wantErr: false,
67+
}, {
68+
name: "with bad check",
69+
script: v1alpha1.Script{
70+
Content: "foo",
71+
SkipLogOutput: true,
72+
Check: &v1alpha1.Check{
73+
Value: map[string]interface{}{
74+
"(foo('bar'))": true,
75+
},
76+
},
77+
},
78+
basePath: "..",
79+
namespace: "test-namespace",
80+
wantErr: true,
81+
}, {
82+
name: "with bad check",
83+
script: v1alpha1.Script{
84+
Content: "cat operation.go",
85+
SkipLogOutput: true,
86+
Check: &v1alpha1.Check{
87+
Value: map[string]interface{}{
88+
"(foo('bar'))": true,
89+
},
90+
},
91+
},
92+
basePath: "..",
93+
namespace: "test-namespace",
94+
wantErr: true,
6795
}}
6896
for _, tt := range tests {
6997
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)