Comments (13)
Hi @shivaDS
testenv.BeforeEachTest
is executed right before defined Go test functions.
So, for you to see BeforeEachTest
executed, you need to define a Go test function, which I don't see in your example.
For instance, when you run the following example,
the framework will execute your BeforeEachTest
before it runs test function TestSomeCode
:
var testenv env.Env
func TestMain(m *testing.M) {
cfg, err := envconf.NewFromFlags()
if err != nil {
log.Fatalf("failed to load env config: %s", err)
}
testenv = env.NewWithConfig(cfg)
testenv.Setup(
envfuncs.InstallTanzuCli(),
)
testenv.Finish()
testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
t.Log("Its before test function")
return ctx, nil
})
os.Exit(testenv.Run(m))
}
func TestSomeCode(t *testing.T){
<insert-test-code>
}
from e2e-framework.
package log_test
import (
"context"
"envfuncs"
//"log"
"os"
"testing"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
)
var testenv env.Environment
func TestMain(m *testing.M) {
testenv = env.New()
testenv.Setup(
envfuncs.InstallTanzuCli(),
)
testenv.Finish()
testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
t.Log("Its before test function")
return ctx, nil
})
os.Exit(testenv.Run(m))
}
func TestSingleclusterInnerloopBasicSupplychainLocalSource(t *testing.T) {
t.Log("its test case")
}
from e2e-framework.
module LogsPackage
go 1.19
require sigs.k8s.io/e2e-framework v0.3.0
from e2e-framework.
hi @vladimirvivien I have added the complete code. Here the log in BeforeEachTest is not getting executed with both testing logger and "log" package logger
from e2e-framework.
Hi @shivaDS
Thanks for the your example. As I explained, the BeforeEachTest
callback will get executed right before the TestSingleclusterInnerloopBasicSupplychainLocalSource
test function is executed.
Specifically for your example, you should see "Its before test function"
prior to "its test case"
.
When you run the test, make sure to use the -v
to see log output:
go test -v .
Otherwise, you will not see the t.Log output.
Hope that helps.
from e2e-framework.
Hi @vladimirvivien ,
Thanks for your inputs. I am running using the command go test . -v
Still I couldn't see that log.
package log_test
import (
"context"
"envfuncs"
"os"
"testing"
"sigs.k8s.io/e2e-framework/pkg/env"
"sigs.k8s.io/e2e-framework/pkg/envconf"
)
var testenv env.Environment
func TestMain(m *testing.M) {
testenv = env.New()
testenv.Setup(
envfuncs.InstallTanzuCli(),
)
testenv.Finish()
testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
t.Log("Its before test function")
return ctx, nil
})
os.Exit(testenv.Run(m))
}
func TestSingleclusterInnerloopBasicSupplychainLocalSource(t *testing.T) {
t.Log("its test case")
}
// func setupTest(t *testing.T) func(t *testing.T) {
// log.Println("setup test")
// return func(t *testing.T) {
// log.Println("teardown test")
// }
// }
// func createNSForTest(ctx context.Context, cfg *envconf.Config, t *testing.T, runID string) (context.Context, error) {
// ns := envconf.RandomName(runID, 10)
// // ctx = context.WithValue(ctx, GetNamespaceKey(t), ns)
// t.Logf("Creating NS %v for test %v", ns, t.Name())
// // nsObj := v1.Namespace{}
// // nsObj.Name = ns
// return ctx, nil
// }
module LogsPackage
go 1.19
require sigs.k8s.io/e2e-framework v0.3.0
The output I get is,
dshiva@dshiva206HL log_test % go test -v .
2024/01/13 22:52:11 In env function
=== RUN TestSingleclusterInnerloopBasicSupplychainLocalSource
main_test.go:36: its test case
--- PASS: TestSingleclusterInnerloopBasicSupplychainLocalSource (0.00s)
PASS
ok LogsPackage/log_test (cached)
from e2e-framework.
@shivaDS
Did you figure this out? Do you think it's a bug ?
from e2e-framework.
@vladimirvivien
I am unable to make it work. Since I am new to golang and e2e-framework, I find it bit hard to understand why it is not working. So I cannot confirm whether it is really a bug
from e2e-framework.
@shivaDS Apologies for the late reply as I was super busy.
But, the following shows how the {Before,After}EachTestest
works.
For it to work you need the followings:
- You need a TestFunction
- You also need features and assessments to be defined as shown below:
Hope this helps
var testenv env.Environment
func TestMain(m *testing.M) {
testenv = env.New()
testenv.Setup(func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
fmt.Println("** Setting up e2e test...")
return ctx, nil
})
testenv.BeforeEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
fmt.Printf(" --> Executing BeforeTest: test %s \n", t.Name())
return ctx, nil
})
testenv.BeforeEachFeature(func(ctx context.Context, cfg *envconf.Config, t *testing.T, f features.Feature) (context.Context, error) {
fmt.Printf(" > Executing BeforeFeature: %s \n", f.Name())
return ctx, nil
})
testenv.AfterEachFeature(func(ctx context.Context, cfg *envconf.Config, t *testing.T, f features.Feature) (context.Context, error) {
fmt.Printf(" > Executing AfterFeature: %s \n", f.Name())
return ctx, nil
})
testenv.AfterEachTest(func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error) {
fmt.Printf(" --> Executing AfterTest: %s \n", t.Name())
return ctx, nil
})
testenv.Finish(func(ctx context.Context, _ *envconf.Config) (context.Context, error) {
fmt.Println("** Finishing e2e test ")
return ctx, nil
})
os.Exit(testenv.Run(m))
}
func TestSomething(t *testing.T) {
// calls testenv.BeforeEachFeature here
f1 := features.New("Feature 1").
Assess("Assessment 1", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
return ctx
})
// calls testenv.AfterEachFeature here
// calls testenv.BeforeEachFeature here
f2 := features.New("Feature 2").
Assess("Assessment 2", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
return ctx
})
// calls testenv.AfterEachFeature here
// testevn.BeforeEachTest
testenv.Test(t, f1.Feature(), f2.Feature())
// testenv.AfterEachTest
}
When you run the previous code, you will get the following
go test -v .
** Setting up e2e test...
=== RUN TestSomething
--> Executing BeforeTest: test TestSomething
> Executing BeforeFeature: Feature 1
=== RUN TestSomething/Feature_1
=== RUN TestSomething/Feature_1/Assessment_1
> Executing AfterFeature: Feature 1
> Executing BeforeFeature: Feature 2
=== RUN TestSomething/Feature_2
=== RUN TestSomething/Feature_2/Assessment_2
> Executing AfterFeature: Feature 2
--> Executing AfterTest: TestSomething
--- PASS: TestSomething (0.00s)
--- PASS: TestSomething/Feature_1 (0.00s)
--- PASS: TestSomething/Feature_1/Assessment_1 (0.00s)
--- PASS: TestSomething/Feature_2 (0.00s)
--- PASS: TestSomething/Feature_2/Assessment_2 (0.00s)
PASS
** Finishing e2e test
ok e2e-framework/workbench 0.679s
from e2e-framework.
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle stale
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
from e2e-framework.
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Mark this issue as fresh with
/remove-lifecycle rotten
- Close this issue with
/close
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
from e2e-framework.
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied - After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied - After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closed
You can:
- Reopen this issue with
/reopen
- Mark this issue as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
from e2e-framework.
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
In response to this:
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
- After 90d of inactivity,
lifecycle/stale
is applied- After 30d of inactivity since
lifecycle/stale
was applied,lifecycle/rotten
is applied- After 30d of inactivity since
lifecycle/rotten
was applied, the issue is closedYou can:
- Reopen this issue with
/reopen
- Mark this issue as fresh with
/remove-lifecycle rotten
- Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
from e2e-framework.
Related Issues (20)
- Calling `Config`'s `Client()` in tests running parallel yields a data race HOT 6
- Create Kind Cluster without test Function HOT 6
- Allow adding custom labels and annotations when creating namespace HOT 3
- Ambiguous call to `cfg.Client()` in `CreateClusterWithConfig` HOT 4
- ,
- Do not share config across tests HOT 3
- Why does `-parallel` and `-fail-fast` can't be used together? HOT 8
- Running `t.FailNow()` in Assess does not fail the following assess HOT 4
- decoder.ApplyWithManifestDir fails to decode yaml with comments in it HOT 5
- Importing "sigs.k8s.io/e2e-framework/klient/conf" causes: ` k8s.io/api/flowcontrol/v1alpha1: module k8s.io/api@latest found (v0.29.3), but does not contain package k8s.io/api/flowcontrol/v1alpha1` HOT 7
- Better error output from Kwok provider HOT 2
- Embedded Local Registry HOT 4
- Test suite is executed even if the setup failed HOT 2
- CLI flags for "running only given features" will skip whole test if a feature in the env doesn't match the criteria. HOT 2
- Instructions in README are outdated and use deprecated functions HOT 5
- `Flux` Integration test with `kyverno` is flaking HOT 1
- imdario/mergo module rename is creating issues with go mod tidy HOT 2
- Handling of interrupt signal during long running tests HOT 1
- Cannot use features.TableRow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from e2e-framework.