Closed iholder101 closed 1 year ago
FWIW, I see that in a LOT of tests (if not all) in the Kubernetes repository the initialization is not made within a BeforeEach block:
kubernetes]> grep "f := framework.NewDefaultFramework(" . -R -B1
/test/e2e/apimachinery/apiserver_identity.go-82-var _ = SIGDescribe("kube-apiserver identity [Feature:APIServerIdentity]", func() {
./test/e2e/apimachinery/apiserver_identity.go:83: f := framework.NewDefaultFramework("kube-apiserver-identity")
--
./test/e2e/apimachinery/apply.go-47-var _ = SIGDescribe("ServerSideApply", func() {
./test/e2e/apimachinery/apply.go:48: f := framework.NewDefaultFramework("apply")
--
./test/e2e/apimachinery/chunking.go-47-var _ = SIGDescribe("Servers with support for API chunking", func() {
./test/e2e/apimachinery/chunking.go:48: f := framework.NewDefaultFramework("chunking")
--
./test/e2e/apimachinery/crd_publish_openapi.go-54-var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", func() {
./test/e2e/apimachinery/crd_publish_openapi.go:55: f := framework.NewDefaultFramework("crd-publish-openapi")
--
./test/e2e/apimachinery/crd_validation_rules.go-38-var _ = SIGDescribe("CustomResourceValidationRules [Privileged:ClusterAdmin]", func() {
./test/e2e/apimachinery/crd_validation_rules.go:39: f := framework.NewDefaultFramework("crd-validation-expressions")
--
Am I missing something?
hey @iholder101 - my understanding is that the k8s framework
package is designed to augment Ginkgo by wrapping around several Ginkgo constructs to present a consistent interface for the k8s test suite. It's designed to build and configure Ginkgo nodes and is aware of the subtleties around test pollution/variable reuse and is designed to be built and invoked during the Tree Construction phase.
All to say: don't worry about using framework
the way most k8s suites use it. That's how its designed to be used. The test pollution guidance applies to variables that are reused and potentially mutated within tests. framework
is used to help construct tests.
If you'd like to learn more I'd encourage you to ask questions over at #sig-testing in the k8s slack channel.
Thanks a lot @onsi! Appreciate it!
However, I would say that maybe the error could be improved in that scenario
In my test, I've tried to follow the Avoid Spec Pollution: Don't Initialize Variables in Container Nodes rule.
Therefore, I've replaced this code:
With:
But after doing so, I'm getting the following error:
I'm not sure what the problem is, and the error description doesn't make a lot of sense for me.
Under this
Describe
I have a couple ofContext
s, containingBeforeEach
themselves, andIt
s. I'd be happy to provide more information if necessary.Thanks in advance.