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

Custom flags for test local (no go test ones) #1476

Closed
smiklosovic opened this issue May 23, 2019 · 7 comments · Fixed by #1509
Closed

Custom flags for test local (no go test ones) #1476

smiklosovic opened this issue May 23, 2019 · 7 comments · Fixed by #1509
Assignees
Labels
area/testing Issue related to testing the operator-sdk and subcomponents kind/feature Categorizes issue or PR as related to a new feature.

Comments

@smiklosovic
Copy link

smiklosovic commented May 23, 2019

Feature Request

Is your feature request related to a problem? Please describe.

I see there in memcached example in main that you are doing flag.String("image") but this flag is set in stone in operator-sdk in test command.

If I want to add my flag (as I have other properties to set, specific to my test), I can not propagate any to "test local" because operator-sdk and go test itself does not recognise them.

Describe the solution you'd like

I want to be able to specify my own additional flags.

@lilic lilic added kind/feature Categorizes issue or PR as related to a new feature. area/testing Issue related to testing the operator-sdk and subcomponents labels May 24, 2019
@AlexNPavel
Copy link
Contributor

You should be able to pass the flags to your test using --go-test-flags. That flag simply appends the string you give it (split by spaces) to go test, which then passes it to the test that is being run if it does not match one of go test's own flags. The only requirement would be putting the code to add the flags before the call to test.MainEntry(m), the same way that the sdk's own e2e tests do.

@smiklosovic
Copy link
Author

@AlexNPavel I was doing that, the go test way with my flags, but I remember that it said that go test does no recognise these flags I am trying to pass and it failed. I am doing it via env properties instead. Are you 100% I can do that?

@smiklosovic
Copy link
Author

smiklosovic commented May 24, 2019

image flag is in operator-sdk test subcommand itself so it is recognised hence parsed from flag but I have not seen any other case when something completely custom is passed to that.

nikhil-thomas added a commit to nikhil-thomas/operator-sdk that referenced this issue Jun 1, 2019
This patch adds `--local-operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves operator-framework#1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
@nikhil-thomas
Copy link
Contributor

nikhil-thomas commented Jun 1, 2019

You should be able to pass the flags to your test using --go-test-flags. That flag simply appends the string you give it (split by spaces) to go test, which then passes it to the test that is being run if it does not match one of go test's own flags. The only requirement would be putting the code to add the flags before the call to test.MainEntry(m), the same way that the sdk's own e2e tests do.

@AlexNPavel this works only if the flag is being used inside the test code. I believe what @smiklosovic is asking for is a way to pass a flag to operator code under test.

ie, an equivalent for --operator-flags flag in
operator-sdk up local --operator-flags command.

At present, if we use --go-test-flags, the unused flags it will not be passed to the operator code when the operator code is run locally (not on cluster).

here:

localCmd = exec.Command(outputBinName)

@nikhil-thomas
Copy link
Contributor

nikhil-thomas commented Jun 1, 2019

i have made a PR addressing this issue.
Could you guys take a look. #1509

nikhil-thomas added a commit to nikhil-thomas/operator-sdk that referenced this issue Jun 2, 2019
This patch adds `--operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves operator-framework#1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
nikhil-thomas added a commit to nikhil-thomas/operator-sdk that referenced this issue Jun 2, 2019
This patch adds `--operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves operator-framework#1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
nikhil-thomas added a commit to nikhil-thomas/operator-sdk that referenced this issue Jun 2, 2019
This patch adds `--operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves operator-framework#1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
@smiklosovic
Copy link
Author

smiklosovic commented Jun 2, 2019

@nikhil-thomas I want to do something like this

https://github.com/operator-framework/operator-sdk/blob/master/test/e2e/main_test.go#L27

On whatever flag, not just image.

(after looking on PR it seems like that's what it does!)

nikhil-thomas added a commit to nikhil-thomas/operator-sdk that referenced this issue Jun 3, 2019
This patch adds `--local-operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves operator-framework#1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
@nikhil-thomas
Copy link
Contributor

nikhil-thomas commented Jun 3, 2019

yes, the idea is to pass any flag which is defined in the operator code.
for development, we have
operator-sdk up local --operator-flags "flag1=val1 flag2=val2"

my PR adds that functionality to --up-local testing
operator-sdk test lcoal --namespace test-operator-namespace --up-local --local-operator-flags "flag1=val1 flag2=val2"

lilic pushed a commit that referenced this issue Jun 5, 2019
This patch adds `--local-operator-flags` to
`operator-sdk test local --up-local` command

It is prvides the functionalisty provided by
`--operator-flags` flag in `operator-sdk up local --operator-flags` command.

At present there is no way to pass command line flags to an operator
while testing using `operator-sdk test local --up-local` command.

There is a flag `--go-test-flags` but it cannot be used to pass flags to
the operator code being tested using `--up-local` flag

This resolves #1476 : **Custom flags for test local (no go test ones)**

Signed-off-by: Nikhil Thomas <[email protected] >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Issue related to testing the operator-sdk and subcomponents kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants