Skip to content

Commit 9b0a996

Browse files
committed
fixes
1 parent 1222fc8 commit 9b0a996

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

pkg/metrics/generate_integration_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"sigs.k8s.io/controller-tools/pkg/genall"
2929
"sigs.k8s.io/controller-tools/pkg/loader"
3030
"sigs.k8s.io/controller-tools/pkg/markers"
31+
"sigs.k8s.io/controller-tools/pkg/metrics/internal/config"
3132
)
3233

3334
func Test_Generate(t *testing.T) {
@@ -68,28 +69,33 @@ func Test_Generate(t *testing.T) {
6869
t.Error(err)
6970
}
7071

71-
foo := out.buf.String()
72-
fmt.Println("<<>>")
73-
fmt.Println(foo)
74-
fmt.Println("<<>>")
7572
output := strings.Split(out.buf.String(), "\n---\n")
7673

77-
if len(output) != 2 {
74+
header := fmt.Sprintf(headerText, "(devel)", config.KubeStateMetricsVersion)
75+
76+
if len(output) != 3 {
7877
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]),
7984
}
8085

8186
t.Log("Comparing output to testdata to check for regressions")
8287

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])
8590

8691
expectedRaw, err := os.ReadFile(path.Clean(path.Join(cwd, "testdata", golden)))
8792
if err != nil {
8893
t.Error(err)
94+
return
8995
}
9096

9197
// Remove leading `---` and trim newlines
92-
generated := strings.TrimSpace(strings.TrimPrefix(generatedRaw, "---"))
98+
generated := strings.TrimSpace(strings.TrimPrefix(generatedData[golden], "---"))
9399
expected := strings.TrimSpace(strings.TrimPrefix(string(expectedRaw), "---"))
94100

95101
diff := cmp.Diff(expected, generated)
@@ -101,6 +107,7 @@ func Test_Generate(t *testing.T) {
101107
t.Logf("Expected output to match file `testdata/%s` but it does not.", golden)
102108
t.Logf("If the change is intended, use `go generate ./pkg/metrics/testdata` to regenerate the `testdata/%s` file.", golden)
103109
t.Errorf("Detected a diff between the output of the integration test and the file `testdata/%s`.", golden)
110+
return
104111
}
105112
}
106113
}

pkg/metrics/generator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func (g Generator) RegisterMarkers(into *ctrlmarkers.Registry) error {
5555
return nil
5656
}
5757

58-
const headerText = `---
59-
# Generated by controller-gen version %s
58+
const headerText = `# Generated by controller-gen version %s
6059
# Generated based on types for kube-state-metrics %s
6160
`
6261

pkg/metrics/markers/zz_generated.markerhelp.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/metrics/testdata/metrics.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
# Generated by controller-gen version (devel)
32
# Generated based on types for kube-state-metrics v2.13.0
43
---

0 commit comments

Comments
 (0)