Skip to content

Commit a17a392

Browse files
authored
Merge pull request kubernetes#70939 from smarterclayton/skip_delta
e2e: Show the caller's stack for Skipf() instead of the local one
2 parents 9f40607 + 68090bf commit a17a392

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

test/e2e/framework/util.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -286,95 +286,99 @@ func FailfWithOffset(offset int, format string, args ...interface{}) {
286286
ginkgowrapper.Fail(nowStamp()+": "+msg, 1+offset)
287287
}
288288

289-
func Skipf(format string, args ...interface{}) {
289+
func skipInternalf(caller int, format string, args ...interface{}) {
290290
msg := fmt.Sprintf(format, args...)
291291
log("INFO", msg)
292-
ginkgowrapper.Skip(nowStamp() + ": " + msg)
292+
ginkgowrapper.Skip(msg, caller+1)
293+
}
294+
295+
func Skipf(format string, args ...interface{}) {
296+
skipInternalf(1, format, args...)
293297
}
294298

295299
func SkipUnlessNodeCountIsAtLeast(minNodeCount int) {
296300
if TestContext.CloudConfig.NumNodes < minNodeCount {
297-
Skipf("Requires at least %d nodes (not %d)", minNodeCount, TestContext.CloudConfig.NumNodes)
301+
skipInternalf(1, "Requires at least %d nodes (not %d)", minNodeCount, TestContext.CloudConfig.NumNodes)
298302
}
299303
}
300304

301305
func SkipUnlessNodeCountIsAtMost(maxNodeCount int) {
302306
if TestContext.CloudConfig.NumNodes > maxNodeCount {
303-
Skipf("Requires at most %d nodes (not %d)", maxNodeCount, TestContext.CloudConfig.NumNodes)
307+
skipInternalf(1, "Requires at most %d nodes (not %d)", maxNodeCount, TestContext.CloudConfig.NumNodes)
304308
}
305309
}
306310

307311
func SkipUnlessAtLeast(value int, minValue int, message string) {
308312
if value < minValue {
309-
Skipf(message)
313+
skipInternalf(1, message)
310314
}
311315
}
312316

313317
func SkipIfProviderIs(unsupportedProviders ...string) {
314318
if ProviderIs(unsupportedProviders...) {
315-
Skipf("Not supported for providers %v (found %s)", unsupportedProviders, TestContext.Provider)
319+
skipInternalf(1, "Not supported for providers %v (found %s)", unsupportedProviders, TestContext.Provider)
316320
}
317321
}
318322

319323
func SkipUnlessLocalEphemeralStorageEnabled() {
320324
if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
321-
Skipf("Only supported when %v feature is enabled", features.LocalStorageCapacityIsolation)
325+
skipInternalf(1, "Only supported when %v feature is enabled", features.LocalStorageCapacityIsolation)
322326
}
323327
}
324328

325329
func SkipUnlessSSHKeyPresent() {
326330
if _, err := GetSigner(TestContext.Provider); err != nil {
327-
Skipf("No SSH Key for provider %s: '%v'", TestContext.Provider, err)
331+
skipInternalf(1, "No SSH Key for provider %s: '%v'", TestContext.Provider, err)
328332
}
329333
}
330334

331335
func SkipUnlessProviderIs(supportedProviders ...string) {
332336
if !ProviderIs(supportedProviders...) {
333-
Skipf("Only supported for providers %v (not %s)", supportedProviders, TestContext.Provider)
337+
skipInternalf(1, "Only supported for providers %v (not %s)", supportedProviders, TestContext.Provider)
334338
}
335339
}
336340

337341
func SkipUnlessMultizone(c clientset.Interface) {
338342
zones, err := GetClusterZones(c)
339343
if err != nil {
340-
Skipf("Error listing cluster zones")
344+
skipInternalf(1, "Error listing cluster zones")
341345
}
342346
if zones.Len() <= 1 {
343-
Skipf("Requires more than one zone")
347+
skipInternalf(1, "Requires more than one zone")
344348
}
345349
}
346350

347351
func SkipIfMultizone(c clientset.Interface) {
348352
zones, err := GetClusterZones(c)
349353
if err != nil {
350-
Skipf("Error listing cluster zones")
354+
skipInternalf(1, "Error listing cluster zones")
351355
}
352356
if zones.Len() > 1 {
353-
Skipf("Requires at most one zone")
357+
skipInternalf(1, "Requires at most one zone")
354358
}
355359
}
356360

357361
func SkipUnlessClusterMonitoringModeIs(supportedMonitoring ...string) {
358362
if !ClusterMonitoringModeIs(supportedMonitoring...) {
359-
Skipf("Only next monitoring modes are supported %v (not %s)", supportedMonitoring, TestContext.ClusterMonitoringMode)
363+
skipInternalf(1, "Only next monitoring modes are supported %v (not %s)", supportedMonitoring, TestContext.ClusterMonitoringMode)
360364
}
361365
}
362366

363367
func SkipUnlessPrometheusMonitoringIsEnabled(supportedMonitoring ...string) {
364368
if !TestContext.EnablePrometheusMonitoring {
365-
Skipf("Skipped because prometheus monitoring is not enabled")
369+
skipInternalf(1, "Skipped because prometheus monitoring is not enabled")
366370
}
367371
}
368372

369373
func SkipUnlessMasterOSDistroIs(supportedMasterOsDistros ...string) {
370374
if !MasterOSDistroIs(supportedMasterOsDistros...) {
371-
Skipf("Only supported for master OS distro %v (not %s)", supportedMasterOsDistros, TestContext.MasterOSDistro)
375+
skipInternalf(1, "Only supported for master OS distro %v (not %s)", supportedMasterOsDistros, TestContext.MasterOSDistro)
372376
}
373377
}
374378

375379
func SkipUnlessNodeOSDistroIs(supportedNodeOsDistros ...string) {
376380
if !NodeOSDistroIs(supportedNodeOsDistros...) {
377-
Skipf("Only supported for node OS distro %v (not %s)", supportedNodeOsDistros, TestContext.NodeOSDistro)
381+
skipInternalf(1, "Only supported for node OS distro %v (not %s)", supportedNodeOsDistros, TestContext.NodeOSDistro)
378382
}
379383
}
380384

@@ -389,21 +393,21 @@ func SkipUnlessSecretExistsAfterWait(c clientset.Interface, name, namespace stri
389393
}
390394
return true, nil
391395
}) != nil {
392-
Skipf("Secret %v in namespace %v did not exist after timeout of %v", name, namespace, timeout)
396+
skipInternalf(1, "Secret %v in namespace %v did not exist after timeout of %v", name, namespace, timeout)
393397
}
394398
Logf("Secret %v in namespace %v found after duration %v", name, namespace, time.Since(start))
395399
}
396400

397401
func SkipUnlessTaintBasedEvictionsEnabled() {
398402
if !utilfeature.DefaultFeatureGate.Enabled(features.TaintBasedEvictions) {
399-
Skipf("Only supported when %v feature is enabled", features.TaintBasedEvictions)
403+
skipInternalf(1, "Only supported when %v feature is enabled", features.TaintBasedEvictions)
400404
}
401405
}
402406

403407
func SkipIfContainerRuntimeIs(runtimes ...string) {
404408
for _, runtime := range runtimes {
405409
if runtime == TestContext.ContainerRuntime {
406-
Skipf("Not supported under container runtime %s", runtime)
410+
skipInternalf(1, "Not supported under container runtime %s", runtime)
407411
}
408412
}
409413
}
@@ -414,7 +418,7 @@ func RunIfContainerRuntimeIs(runtimes ...string) {
414418
return
415419
}
416420
}
417-
Skipf("Skipped because container runtime %q is not in %s", TestContext.ContainerRuntime, runtimes)
421+
skipInternalf(1, "Skipped because container runtime %q is not in %s", TestContext.ContainerRuntime, runtimes)
418422
}
419423

420424
func RunIfSystemSpecNameIs(names ...string) {
@@ -423,7 +427,7 @@ func RunIfSystemSpecNameIs(names ...string) {
423427
return
424428
}
425429
}
426-
Skipf("Skipped because system spec name %q is not in %v", TestContext.SystemSpecName, names)
430+
skipInternalf(1, "Skipped because system spec name %q is not in %v", TestContext.SystemSpecName, names)
427431
}
428432

429433
func ProviderIs(providers ...string) bool {
@@ -497,7 +501,7 @@ func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersio
497501
Failf("Failed to get server version: %v", err)
498502
}
499503
if !gte {
500-
Skipf("Not supported for server versions before %q", v)
504+
skipInternalf(1, "Not supported for server versions before %q", v)
501505
}
502506
}
503507

@@ -507,7 +511,7 @@ func SkipIfMissingResource(dynamicClient dynamic.Interface, gvr schema.GroupVers
507511
if err != nil {
508512
// not all resources support list, so we ignore those
509513
if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) {
510-
Skipf("Could not find %s resource, skipping test: %#v", gvr, err)
514+
skipInternalf(1, "Could not find %s resource, skipping test: %#v", gvr, err)
511515
}
512516
Failf("Unexpected error getting %v: %v", gvr, err)
513517
}
@@ -1943,7 +1947,7 @@ func SkipUnlessKubectlVersionGTE(v *utilversion.Version) {
19431947
Failf("Failed to get kubectl version: %v", err)
19441948
}
19451949
if !gte {
1946-
Skipf("Not supported for kubectl versions before %q", v)
1950+
skipInternalf(1, "Not supported for kubectl versions before %q", v)
19471951
}
19481952
}
19491953

0 commit comments

Comments
 (0)