Skip to content

Commit b768ed7

Browse files
author
Antoine Pelisse
committed
Add new test that uses an actual production-like pod
1 parent e9173f4 commit b768ed7

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

merge/pod_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package merge_test
18+
19+
import (
20+
"io/ioutil"
21+
"path/filepath"
22+
"testing"
23+
24+
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
25+
"sigs.k8s.io/structured-merge-diff/typed"
26+
)
27+
28+
func testdata(file string) string {
29+
return filepath.Join("..", "internal", "testdata", file)
30+
}
31+
32+
func read(file string) []byte {
33+
s, err := ioutil.ReadFile(file)
34+
if err != nil {
35+
panic(err)
36+
}
37+
return s
38+
}
39+
40+
var podParser = func() typed.ParseableType {
41+
s := read(testdata("k8s-schema.yaml"))
42+
parser, err := typed.NewParser(typed.YAMLObject(s))
43+
if err != nil {
44+
panic(err)
45+
}
46+
return parser.Type("io.k8s.api.core.v1.Pod")
47+
}()
48+
49+
func BenchmarkPodUpdates(b *testing.B) {
50+
test := TestCase{
51+
Ops: []Operation{
52+
Update{
53+
Manager: "controller",
54+
APIVersion: "v1",
55+
Object: typed.YAMLObject(read(testdata("pod.yaml"))),
56+
},
57+
},
58+
}
59+
60+
test.PreprocessOperations(podParser)
61+
62+
b.ReportAllocs()
63+
b.ResetTimer()
64+
for n := 0; n < b.N; n++ {
65+
if err := test.Bench(podParser); err != nil {
66+
b.Fatal(err)
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)