-
Notifications
You must be signed in to change notification settings - Fork 34
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
upgrade cli package, fix drone 1.x token env variable issue #127
upgrade cli package, fix drone 1.x token env variable issue #127
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just a couple of "nice to haves" ..
- Update references to
TOKEN
in documentation - Update references to
TOKEN
inMakefile
- Add unit tests for
token
param precedence? Something like:
func TestTokenParamPrecedence(t *testing.T) {
// Reset environment
os.Clearenv()
// Set both token-related environment variables
os.Setenv("TOKEN", "from-token-env")
os.Setenv("PLUGIN_TOKEN", "from-plugin-token-env")
// Set token CLI argument
set := flag.NewFlagSet("prefer-arg-over-any-env", 0)
c := cli.NewContext(nil, set, nil)
set.String("token", "from-token-arg", "")
// token CLI argument takes precedence over either environment variable
assert.Equal(t, c.String("token"), "from-token-arg")
// Reset environment
os.Clearenv()
// Set both token-related environment variables
os.Setenv("TOKEN", "from-token-env")
os.Setenv("PLUGIN_TOKEN", "from-plugin-token-env")
// Set CLI arguments without token
set = flag.NewFlagSet("prefer-plugin-token-env", 0)
c = cli.NewContext(nil, set, nil)
// PLUGIN_TOKEN environment variable takes precedence over TOKEN environment variable
assert.Equal(t, c.String("token"), "from-plugin-token-env")
// Reset environment
os.Clearenv()
// Set only TOKEN environment variable
os.Setenv("TOKEN", "from-token-env")
// Set without token CLI argument
set = flag.NewFlagSet("prefer-token-env", 0)
c = cli.NewContext(nil, set, nil)
// TOKEN environment variable supported without token CLI argument or PLUGIN_TOKEN environment variable
assert.Equal(t, c.String("token"), "from-token-env")
// ...
}
Thanks for the comments @montmanu - i updated the docs and Makefile but still trying to get the tests to work, I don't think |
main_test.go
Outdated
set.String("token", "from-token-arg", "") | ||
|
||
// token CLI argument takes precedence over either environment variable | ||
assert.Equal(t, "from-token-arg", c.String("token")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@montmanu - there more I think about these tests, the less they make sense.
This would really just tests that the library is working, none of this invokes code any plugin code
(i also still haven't figured out how to trigger env parsing of flags without using the full cli.App()
thing but that's another problem)
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree that its not testing much of the plugin's code, but its also a somewhat critical part of the plugin's public API, so a bit worried that from a user's e2e POV, we're not well covered on the token parsing / selection logic..
maybe it would be easier for us to figure out a way to cover that via e2e tests? build the plugin, trigger some downstream ci process that would run that version of the plugin against all versions of drone supported by the plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed this is important. Let me try something, i think i have an idea what might work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I found a way to get the tests to do something meaningful. Might actually want to replace some others like TestCheckParams
with the same App.Run() pattern to test the real plugin-code.
fb233f3
to
9771e44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes!
This should fix #119 by picking up both the
PLUGIN_TOKEN
(drone 1.x) andTOKEN
(drone 0.x) env variables (see main.go line 93)I upgraded the cli package to v2 before I noticed that you can do this in v1 as well. I can undo that change if you prefer so.