e2e framework: enable extending TimeoutContext
If we were to add new fields in TimeoutContext, the current users of NewFrameworkWithCustomTimeouts might run into failures unless they get modified to also set those new fields. This is error-prone. A better approach is to let users of NewFrameworkWithCustomTimeouts override fields by setting just those and use the normal defaults for the others.
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -144,10 +145,19 @@ type Options struct {
|
||||
GroupVersion *schema.GroupVersion
|
||||
}
|
||||
|
||||
// NewFrameworkWithCustomTimeouts makes a framework with with custom timeouts.
|
||||
// NewFrameworkWithCustomTimeouts makes a framework with custom timeouts.
|
||||
// For timeout values that are zero the normal default value continues to
|
||||
// be used.
|
||||
func NewFrameworkWithCustomTimeouts(baseName string, timeouts *TimeoutContext) *Framework {
|
||||
f := NewDefaultFramework(baseName)
|
||||
f.Timeouts = timeouts
|
||||
in := reflect.ValueOf(timeouts).Elem()
|
||||
out := reflect.ValueOf(f.Timeouts).Elem()
|
||||
for i := 0; i < in.NumField(); i++ {
|
||||
value := in.Field(i)
|
||||
if !value.IsZero() {
|
||||
out.Field(i).Set(value)
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user