Skip to content

Commit 4eb6b39

Browse files
authored
Merge pull request kubernetes#120361 from tnqn/improve-test-log
Improve service unit test failure report
2 parents 19d8280 + 0fb1f59 commit 4eb6b39

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/api/service/util_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
func TestGetLoadBalancerSourceRanges(t *testing.T) {
2828
checkError := func(v string) {
29+
t.Helper()
2930
annotations := make(map[string]string)
3031
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
3132
svc := api.Service{}
@@ -49,6 +50,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
4950
checkError("10.0.0.1")
5051

5152
checkOK := func(v string) utilnet.IPNetSet {
53+
t.Helper()
5254
annotations := make(map[string]string)
5355
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
5456
svc := api.Service{}
@@ -112,6 +114,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
112114

113115
func TestAllowAll(t *testing.T) {
114116
checkAllowAll := func(allowAll bool, cidrs ...string) {
117+
t.Helper()
115118
ipnets, err := utilnet.ParseIPNets(cidrs...)
116119
if err != nil {
117120
t.Errorf("Unexpected error parsing cidrs: %v", cidrs)
@@ -131,6 +134,7 @@ func TestAllowAll(t *testing.T) {
131134

132135
func TestExternallyAccessible(t *testing.T) {
133136
checkExternallyAccessible := func(expect bool, service *api.Service) {
137+
t.Helper()
134138
res := ExternallyAccessible(service)
135139
if res != expect {
136140
t.Errorf("Expected ExternallyAccessible = %v, got %v", expect, res)
@@ -174,6 +178,7 @@ func TestExternallyAccessible(t *testing.T) {
174178

175179
func TestRequestsOnlyLocalTraffic(t *testing.T) {
176180
checkRequestsOnlyLocalTraffic := func(requestsOnlyLocalTraffic bool, service *api.Service) {
181+
t.Helper()
177182
res := RequestsOnlyLocalTraffic(service)
178183
if res != requestsOnlyLocalTraffic {
179184
t.Errorf("Expected requests OnlyLocal traffic = %v, got %v",
@@ -220,6 +225,7 @@ func TestRequestsOnlyLocalTraffic(t *testing.T) {
220225

221226
func TestNeedsHealthCheck(t *testing.T) {
222227
checkNeedsHealthCheck := func(needsHealthCheck bool, service *api.Service) {
228+
t.Helper()
223229
res := NeedsHealthCheck(service)
224230
if res != needsHealthCheck {
225231
t.Errorf("Expected needs health check = %v, got %v",

pkg/api/v1/service/util_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
func TestGetLoadBalancerSourceRanges(t *testing.T) {
2828
checkError := func(v string) {
29+
t.Helper()
2930
annotations := make(map[string]string)
3031
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
3132
svc := v1.Service{}
@@ -49,6 +50,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
4950
checkError("10.0.0.1")
5051

5152
checkOK := func(v string) utilnet.IPNetSet {
53+
t.Helper()
5254
annotations := make(map[string]string)
5355
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
5456
svc := v1.Service{}
@@ -112,6 +114,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
112114

113115
func TestAllowAll(t *testing.T) {
114116
checkAllowAll := func(allowAll bool, cidrs ...string) {
117+
t.Helper()
115118
ipnets, err := utilnet.ParseIPNets(cidrs...)
116119
if err != nil {
117120
t.Errorf("Unexpected error parsing cidrs: %v", cidrs)
@@ -131,6 +134,7 @@ func TestAllowAll(t *testing.T) {
131134

132135
func TestExternallyAccessible(t *testing.T) {
133136
checkExternallyAccessible := func(expect bool, service *v1.Service) {
137+
t.Helper()
134138
res := ExternallyAccessible(service)
135139
if res != expect {
136140
t.Errorf("Expected ExternallyAccessible = %v, got %v", expect, res)
@@ -174,6 +178,7 @@ func TestExternallyAccessible(t *testing.T) {
174178

175179
func TestExternalPolicyLocal(t *testing.T) {
176180
checkExternalPolicyLocal := func(requestsOnlyLocalTraffic bool, service *v1.Service) {
181+
t.Helper()
177182
res := ExternalPolicyLocal(service)
178183
if res != requestsOnlyLocalTraffic {
179184
t.Errorf("Expected requests OnlyLocal traffic = %v, got %v",
@@ -240,6 +245,7 @@ func TestExternalPolicyLocal(t *testing.T) {
240245

241246
func TestNeedsHealthCheck(t *testing.T) {
242247
checkNeedsHealthCheck := func(needsHealthCheck bool, service *v1.Service) {
248+
t.Helper()
243249
res := NeedsHealthCheck(service)
244250
if res != needsHealthCheck {
245251
t.Errorf("Expected needs health check = %v, got %v",
@@ -280,6 +286,7 @@ func TestNeedsHealthCheck(t *testing.T) {
280286

281287
func TestInternalPolicyLocal(t *testing.T) {
282288
checkInternalPolicyLocal := func(expected bool, service *v1.Service) {
289+
t.Helper()
283290
res := InternalPolicyLocal(service)
284291
if res != expected {
285292
t.Errorf("Expected internal local traffic = %v, got %v",

0 commit comments

Comments
 (0)