kubernetes/test/e2e/framework/internal/unittests/framework_test.go
Patrick Ohly 39b6916cbc e2e: add wrapper functions to annotate tests
These wrapper functions set labels in addition to injecting the annotation into
the test text. It then becomes possible to select tests in different ways:

    ginkgo -v --focus="should respect internalTrafficPolicy.*\[FeatureGate:ServiceInternalTrafficPolicy\]"

    ginkgo -v --label-filter="FeatureGate:ServiceInternalTrafficPolicy"

    ginkgo -v --label-filter="Beta"

When a test runs, ginkgo shows it as:

    [It] should respect internalTrafficPolicy=Local Pod to Pod [FeatureGate:ServiceInternalTrafficPolicy] [Beta] [FeatureGate:ServiceInternalTrafficPolicy, Beta]

The test name and the labels at the end are in different colors. Embedding the
annotations inside the text is redundant and only done because users of the e2e
suite might expect it. Also, our tooling that consumes test results currently
doesn't know about ginkgo labels.

Environments, features and node features as described by
https://github.com/kubernetes/enhancements/tree/master/keps/sig-testing/3041-node-conformance-and-features
are also supported.

The framework and thus (at the moment) test/e2e do not have any pre-defined
environments and features. Adding those and modifying tests will follow in
a separate commit.
2023-10-10 18:15:49 +02:00

53 lines
1.5 KiB
Go

/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package unittests_test
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/test/e2e/framework"
)
func TestNewFrameworkWithCustomTimeouts(t *testing.T) {
defaultF := framework.NewDefaultFramework("test")
customTimeouts := &framework.TimeoutContext{
PodStart: 5 * time.Second,
PodDelete: time.Second,
}
customF := framework.NewFrameworkWithCustomTimeouts("test", customTimeouts)
defaultF.Timeouts.PodStart = customTimeouts.PodStart
defaultF.Timeouts.PodDelete = customTimeouts.PodDelete
assert.Equal(t, customF.Timeouts, defaultF.Timeouts)
}
func TestNewFramework(t *testing.T) {
f := framework.NewDefaultFramework("test")
timeouts := reflect.ValueOf(f.Timeouts).Elem()
for i := 0; i < timeouts.NumField(); i++ {
value := timeouts.Field(i)
if value.IsZero() {
t.Errorf("%s in Framework.Timeouts was not set.", reflect.TypeOf(*f.Timeouts).Field(i).Name)
}
}
}