Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify multiple labels when running tests #194

Closed
embano1 opened this issue Jan 26, 2023 · 2 comments · Fixed by #196
Closed

How to specify multiple labels when running tests #194

embano1 opened this issue Jan 26, 2023 · 2 comments · Fixed by #196

Comments

@embano1
Copy link
Contributor

embano1 commented Jan 26, 2023

This example recommends a label key test and values for individual features:

e2e-framework/README.md

Lines 70 to 84 in 8e4361f

WithLabel("type", "pod-count").
Assess("pods from kube-system", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
var pods corev1.PodList
err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods)
if err != nil {
t.Fatal(err)
}
if len(pods.Items) == 0 {
t.Fatal("no pods in namespace kube-system")
}
return ctx
}).Feature()
f2 := features.New("count namespaces").
WithLabel("type", "ns-count").

However, following this logic, I cannot run multiple features with the same label key, e.g.

--labels="feature=feat1,feature=feat2" is not possible (in my current tests the first one is ignored). I guess this is due to the label parsing map used:

func (m LabelsMap) Set(val string) error {

Wondering if we should fix this so I can run multiple features instead of just one when using the same label key.

@vladimirvivien
Copy link
Contributor

vladimirvivien commented Jan 28, 2023

@embano1 thanks for the issue. Are you saying that a features cannot have multiple labels added to it? Or are you saying you just want to run multiple features with the same labels ?

For the latter, you should be able to declare multiple features with the same (or different) labels and run them:

func TestHello_WithSetup(t *testing.T) {
	e := env.NewWithConfig(envconf.New())
	var name string
	f0 := features.New("Hello Feature").
		WithLabel("type", "hello").
		Assess("test message", func(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context {
			result := Hello(name)
			if result != "Hello foobar" {
				t.Error("unexpected message")
			}
			return ctx
		}).Feature()

	  f1 := features.New("Goodbye Feature").
		WithLabel("type", "message").
		Assess("test message", func(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context {
			result := Goodbye(name)
			if result != "Goodbye foobar" {
				t.Error("unexpected message")
			}
			return ctx
		}).Feature()
	e.Test(t, f0, f1)
}

You should be able to select each feature by label as follows:

go run . -args --labels="type=hello, type=goodbye"

If i completely misunderstood your question (or there is a bug), please let us know.

@embano1
Copy link
Contributor Author

embano1 commented Jan 28, 2023

Thx for your response! What I found was that if featureX had label "feature=foo" and featureY had the label "feature=bar if I run go run . -args --labels="feature=foo,feature=bar" only featureY ran. Looking up the code, it seems a map is used which would overwrite labels with the same key i.e. "feature.

A fix would be to use []string as map values.

[Update]
Have a local fix, just need to polish and update some code paths which broke due to the refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants