Skip to content

Commit 8a2620f

Browse files
committed
Name operation tests after their filename
1 parent e3fbe42 commit 8a2620f

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

merge/real_test.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package merge_test
1919
import (
2020
"io/ioutil"
2121
"path/filepath"
22-
"strings"
2322
"testing"
2423

2524
. "sigs.k8s.io/structured-merge-diff/v4/internal/fixture"
@@ -38,10 +37,6 @@ func read(file string) []byte {
3837
return s
3938
}
4039

41-
func lastPart(s string) string {
42-
return s[strings.LastIndex(s, ".")+1:]
43-
}
44-
4540
var parser = func() Parser {
4641
s := read(testdata("k8s-schema.yaml"))
4742
parser, err := typed.NewParser(typed.YAMLObject(s))
@@ -54,28 +49,29 @@ var parser = func() Parser {
5449
func BenchmarkOperations(b *testing.B) {
5550
benches := []struct {
5651
typename string
57-
obj typed.YAMLObject
52+
filename string
5853
}{
5954
{
6055
typename: "io.k8s.api.core.v1.Pod",
61-
obj: typed.YAMLObject(read(testdata("pod.yaml"))),
56+
filename: "pod.yaml",
6257
},
6358
{
6459
typename: "io.k8s.api.core.v1.Node",
65-
obj: typed.YAMLObject(read(testdata("node.yaml"))),
60+
filename: "node.yaml",
6661
},
6762
{
6863
typename: "io.k8s.api.core.v1.Endpoints",
69-
obj: typed.YAMLObject(read(testdata("endpoints.yaml"))),
64+
filename: "endpoints.yaml",
7065
},
7166
{
7267
typename: "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinition",
73-
obj: typed.YAMLObject(read(testdata("prometheus-crd.yaml"))),
68+
filename: "prometheus-crd.yaml",
7469
},
7570
}
7671

7772
for _, bench := range benches {
78-
b.Run(lastPart(bench.typename), func(b *testing.B) {
73+
b.Run(bench.filename, func(b *testing.B) {
74+
obj := typed.YAMLObject(read(testdata(bench.filename)))
7975
tests := []struct {
8076
name string
8177
ops []Operation
@@ -86,7 +82,7 @@ func BenchmarkOperations(b *testing.B) {
8682
Update{
8783
Manager: "controller",
8884
APIVersion: "v1",
89-
Object: bench.obj,
85+
Object: obj,
9086
},
9187
},
9288
},
@@ -96,7 +92,7 @@ func BenchmarkOperations(b *testing.B) {
9692
Apply{
9793
Manager: "controller",
9894
APIVersion: "v1",
99-
Object: bench.obj,
95+
Object: obj,
10096
},
10197
},
10298
},
@@ -106,12 +102,12 @@ func BenchmarkOperations(b *testing.B) {
106102
Apply{
107103
Manager: "controller",
108104
APIVersion: "v1",
109-
Object: bench.obj,
105+
Object: obj,
110106
},
111107
Apply{
112108
Manager: "other-controller",
113109
APIVersion: "v1",
114-
Object: bench.obj,
110+
Object: obj,
115111
},
116112
},
117113
},
@@ -121,12 +117,12 @@ func BenchmarkOperations(b *testing.B) {
121117
Update{
122118
Manager: "controller",
123119
APIVersion: "v1",
124-
Object: bench.obj,
120+
Object: obj,
125121
},
126122
Update{
127123
Manager: "other-controller",
128124
APIVersion: "v1",
129-
Object: bench.obj,
125+
Object: obj,
130126
},
131127
},
132128
},
@@ -136,12 +132,12 @@ func BenchmarkOperations(b *testing.B) {
136132
Update{
137133
Manager: "controller",
138134
APIVersion: "v1",
139-
Object: bench.obj,
135+
Object: obj,
140136
},
141137
Update{
142138
Manager: "other-controller",
143139
APIVersion: "v2",
144-
Object: bench.obj,
140+
Object: obj,
145141
},
146142
},
147143
},

0 commit comments

Comments
 (0)