@@ -28,6 +28,7 @@ import (
28
28
"sigs.k8s.io/controller-tools/pkg/genall"
29
29
"sigs.k8s.io/controller-tools/pkg/loader"
30
30
"sigs.k8s.io/controller-tools/pkg/markers"
31
+ "sigs.k8s.io/controller-tools/pkg/metrics/internal/config"
31
32
)
32
33
33
34
func Test_Generate (t * testing.T ) {
@@ -68,28 +69,33 @@ func Test_Generate(t *testing.T) {
68
69
t .Error (err )
69
70
}
70
71
71
- foo := out .buf .String ()
72
- fmt .Println ("<<>>" )
73
- fmt .Println (foo )
74
- fmt .Println ("<<>>" )
75
72
output := strings .Split (out .buf .String (), "\n ---\n " )
76
73
77
- if len (output ) != 2 {
74
+ header := fmt .Sprintf (headerText , "(devel)" , config .KubeStateMetricsVersion )
75
+
76
+ if len (output ) != 3 {
78
77
t .Error ("Expected two output files, metrics configuration followed by rbac." )
78
+ return
79
+ }
80
+
81
+ generatedData := map [string ]string {
82
+ "metrics.yaml" : header + "---\n " + string (output [1 ]),
83
+ "rbac.yaml" : "---\n " + string (output [2 ]),
79
84
}
80
85
81
86
t .Log ("Comparing output to testdata to check for regressions" )
82
87
83
- for i , golden := range []string {"metrics.yaml" , "rbac.yaml" } {
84
- generatedRaw := strings .TrimSpace (output [i ])
88
+ for _ , golden := range []string {"metrics.yaml" , "rbac.yaml" } {
89
+ // generatedRaw := strings.TrimSpace(output[i])
85
90
86
91
expectedRaw , err := os .ReadFile (path .Clean (path .Join (cwd , "testdata" , golden )))
87
92
if err != nil {
88
93
t .Error (err )
94
+ return
89
95
}
90
96
91
97
// Remove leading `---` and trim newlines
92
- generated := strings .TrimSpace (strings .TrimPrefix (generatedRaw , "---" ))
98
+ generated := strings .TrimSpace (strings .TrimPrefix (generatedData [ golden ] , "---" ))
93
99
expected := strings .TrimSpace (strings .TrimPrefix (string (expectedRaw ), "---" ))
94
100
95
101
diff := cmp .Diff (expected , generated )
@@ -101,6 +107,7 @@ func Test_Generate(t *testing.T) {
101
107
t .Logf ("Expected output to match file `testdata/%s` but it does not." , golden )
102
108
t .Logf ("If the change is intended, use `go generate ./pkg/metrics/testdata` to regenerate the `testdata/%s` file." , golden )
103
109
t .Errorf ("Detected a diff between the output of the integration test and the file `testdata/%s`." , golden )
110
+ return
104
111
}
105
112
}
106
113
}
0 commit comments