mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
ktesting: add Step
Step simplifies using WithStep because it creates a local scope where the same tCtx variable is the one with the step name.
This commit is contained in:
parent
639f86915b
commit
171620765e
@ -41,6 +41,24 @@ func WithStep(tCtx TContext, what string) TContext {
|
|||||||
return WithLogger(sCtx, klog.LoggerWithName(sCtx.Logger(), what))
|
return WithLogger(sCtx, klog.LoggerWithName(sCtx.Logger(), what))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step is useful when the context with the step information is
|
||||||
|
// used more than once:
|
||||||
|
//
|
||||||
|
// ktesting.Step(tCtx, "step 1", func(tCtx ktesting.TContext) {
|
||||||
|
// tCtx.Log(...)
|
||||||
|
// if (... ) {
|
||||||
|
// tCtx.Failf(...)
|
||||||
|
// }
|
||||||
|
// )}
|
||||||
|
//
|
||||||
|
// Inside the callback, the tCtx variable is the one where the step
|
||||||
|
// has been added. This avoids the need to introduce multiple different
|
||||||
|
// context variables and risk of using the wrong one.
|
||||||
|
func Step(tCtx TContext, what string, cb func(tCtx TContext)) {
|
||||||
|
tCtx.Helper()
|
||||||
|
cb(WithStep(tCtx, what))
|
||||||
|
}
|
||||||
|
|
||||||
type stepContext struct {
|
type stepContext struct {
|
||||||
TContext
|
TContext
|
||||||
what string
|
what string
|
||||||
|
Loading…
Reference in New Issue
Block a user