Skip to content

Commit 6f6ac3a

Browse files
author
priyawadhwa
authored
Merge pull request #7880 from n0npax/improve-perf-test-coverage
Improve perf test coverage
2 parents de71233 + 9994f28 commit 6f6ac3a

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

pkg/minikube/perf/binary_test.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors All rights reserved.
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 perf
18+
19+
import (
20+
"strings"
21+
"testing"
22+
)
23+
24+
func TestBinaryName(t *testing.T) {
25+
tests := []struct {
26+
expected string
27+
binary Binary
28+
}{
29+
{
30+
expected: "foo",
31+
binary: Binary{path: "foo", pr: 0},
32+
},
33+
{
34+
expected: "Minikube (PR 1)",
35+
binary: Binary{path: "bar", pr: 1},
36+
},
37+
}
38+
39+
for _, test := range tests {
40+
t.Run(test.expected, func(t *testing.T) {
41+
name := test.binary.Name()
42+
if name != test.expected {
43+
t.Fatalf("Binary name(%v) doesn't match expected name(%v)", name, test.expected)
44+
}
45+
})
46+
47+
}
48+
}
49+
50+
func TestNewBinary(t *testing.T) {
51+
tests := []struct {
52+
input, prNum string
53+
errExpected bool
54+
}{
55+
{
56+
input: prPrefix + "42",
57+
prNum: "42",
58+
},
59+
{
60+
input: "42",
61+
prNum: "42",
62+
},
63+
{
64+
input: prPrefix + "XYZ",
65+
errExpected: true,
66+
},
67+
}
68+
69+
for _, test := range tests {
70+
t.Run(test.input, func(t *testing.T) {
71+
bin, err := NewBinary(test.input)
72+
if err == nil && test.errExpected {
73+
t.Fatalf("Input %v returned unexpected error", test.input)
74+
}
75+
if test.errExpected {
76+
return
77+
}
78+
if bin == nil {
79+
t.Fatalf("Input string(%v) returned unexpected empty binary", test.input)
80+
}
81+
if !strings.Contains(bin.path, test.prNum) {
82+
t.Fatalf("Binary path(%v) doesn't contain expected(%v)", bin.path, test.prNum)
83+
}
84+
})
85+
}
86+
}

0 commit comments

Comments
 (0)