@@ -25,7 +25,6 @@ import (
25
25
"os/exec"
26
26
"path/filepath"
27
27
"strings"
28
- "testing"
29
28
30
29
"k8s.io/apimachinery/pkg/api/meta"
31
30
"k8s.io/apimachinery/pkg/runtime"
@@ -44,7 +43,25 @@ import (
44
43
"sigs.k8s.io/kustomize/kyaml/filesys"
45
44
)
46
45
47
- func NewValidator (t * testing.T , b * scheme.Builder ) * validator {
46
+ // T re-exposes the parts of testing.T we're using as an interface,
47
+ // in order to play more nicely with third-party libraries (e.g. gomega).
48
+ // This helps making these testing utils compatible with the testing strategy
49
+ // generated by kubebuilder.
50
+ //
51
+ // Note that testing.T has a bunch of other things as well; these are just the
52
+ // ones currently in use in this project.
53
+ //
54
+ // See e.g. https://github.com/onsi/ginkgo/blob/master/ginkgo_t_dsl.go#L7-L17
55
+ type T interface {
56
+ Cleanup (func ())
57
+ Errorf (format string , args ... interface {})
58
+ Fatalf (format string , args ... interface {})
59
+ Helper ()
60
+ Logf (format string , args ... interface {})
61
+ TempDir () string
62
+ }
63
+
64
+ func NewValidator (t T , b * scheme.Builder ) * validator {
48
65
v := & validator {T : t , scheme : runtime .NewScheme ()}
49
66
if err := b .AddToScheme (v .scheme ); err != nil {
50
67
t .Fatalf ("error from AddToScheme: %v" , err )
@@ -87,7 +104,7 @@ func NewValidator(t *testing.T, b *scheme.Builder) *validator {
87
104
}
88
105
89
106
type validator struct {
90
- T * testing. T
107
+ T T
91
108
scheme * runtime.Scheme
92
109
TestDir string
93
110
@@ -351,7 +368,7 @@ func (v *validator) Validate(r declarative.Reconciler) {
351
368
}
352
369
}
353
370
354
- func diffFiles (t * testing. T , expectedPath , actual string ) error {
371
+ func diffFiles (t T , expectedPath , actual string ) error {
355
372
t .Helper ()
356
373
writeTmp := func (content string ) (string , error ) {
357
374
tmp , err := os .CreateTemp ("" , "*.yaml" )
0 commit comments