-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: standardize error for prompt #4939
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
Conversation
c429c25 to
c4264f9
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4939 +/- ##
==========================================
- Coverage 61.19% 61.15% -0.04%
==========================================
Files 294 294
Lines 20538 20556 +18
==========================================
+ Hits 12568 12571 +3
- Misses 7076 7088 +12
- Partials 894 897 +3 |
adf7c09 to
aa70ff4
Compare
87e16b0 to
a390711
Compare
|
Getting this test failure now https://github.com/docker/cli/actions/runs/8362281837/job/22892487855?pr=4939#step:4:397 Will look at it tomorrow. Most likely related #4948 |
a390711 to
178de20
Compare
fb48fb2 to
9bc91a8
Compare
--- FAIL: TestConnectAndWait (0.02s)
--- FAIL: TestConnectAndWait/connect_goroutine_exits_after_EOF (0.02s)
socket_test.go:182: timeout hit after 10ms: waiting for connect goroutine to exit
FAIL🤔 Wonder if some flakiness has been introduced in this commit d68cc0e#diff-2b3ea721470acb354ca37a32dc40b7c0ae55bd43397a084adbd922fca5964e20 |
krissetto
left a comment
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.
overall LGTM after some minor nits and what has already been pointed out by the others
Signed-off-by: Alano Terblanche <[email protected]>
9bc91a8 to
7c722c0
Compare
laurazard
left a comment
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
|
@thaJeztah care to take a final look at this? |
|
Could we merge this one? |
thaJeztah
left a comment
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! Overall looks good; had a question about that magic UNIQUEME variable, and noticed some back-tics in the errors.
Honestly (but not for this PR), looking at PromptForConfirmation, I'm slightly wondering if it's doing too much
Lines 92 to 98 in 155dc5e
| func PromptForConfirmation(ctx context.Context, ins io.Reader, outs io.Writer, message string) (bool, error) { | |
| if message == "" { | |
| message = "Are you sure you want to proceed?" | |
| } | |
| message += " [y/N] " | |
| _, _ = fmt.Fprint(outs, message) |
Wondering if;
- haven't checked, but wondered if there's cases where
Nois not the default (so if it should take a default value), but maybe that's not the case. - ☝️ that said, the
[y/N](capitalN) indicates thatNis always considered the default; so even if a caller would want to use a different default, the function appending the[y/N]means that there's not really a choice for them. - we should remove the default message (looks like the only place where we pass an empty string is in a test)
- was even considering if we need the
messageat all, because all it does is print the message (unconditionally), and if that should be left to the caller; - from that perspective I was looking at the
outs io.Writerand if we need it, but that one looks more tricky, as we still want to print the newline 😓
| // set by the compile flags to get around content sha being the same | ||
| var ( | ||
| UNIQUEME string | ||
| ) | ||
|
|
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.
This one doesn't seem to be used anywhere, so could lead to a linter starting to flag it.
Possibly we could avoid that through something silly like _ = UNIQUEME, but slightly curious what the issue was that you ran into; did this cause issues in tests where Go was caching things? Or was there something else?
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.
The e2e tests build a plugin and pushes that to a registry run inside docker (spun up by the tests). That said, for multiple tests doing docker plugin create and docker plugin push you would end up with sha collisions since the source code of the plugin binary built would be the same. The UNIQUEME variable is a way around this, so we can re-build the same plugin binary from the same source code generating a new sha hash.
See these tests for reference
Lines 143 to 181 in 7c722c0
| name: "plugin install", | |
| run: func(t *testing.T) icmd.Cmd { | |
| t.Helper() | |
| skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44")) | |
| pluginDir := testutils.SetupPlugin(t, ctx) | |
| t.Cleanup(pluginDir.Remove) | |
| plugin := "registry:5000/plugin-content-trust-install:latest" | |
| icmd.RunCommand("docker", "plugin", "create", plugin, pluginDir.Path()).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin), defaultCmdOpts...).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin), defaultCmdOpts...).Assert(t, icmd.Success) | |
| return icmd.Command("docker", "plugin", "install", plugin) | |
| }, | |
| }, | |
| { | |
| name: "plugin upgrade", | |
| run: func(t *testing.T) icmd.Cmd { | |
| t.Helper() | |
| skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44")) | |
| pluginLatestDir := testutils.SetupPlugin(t, ctx) | |
| t.Cleanup(pluginLatestDir.Remove) | |
| pluginNextDir := testutils.SetupPlugin(t, ctx) | |
| t.Cleanup(pluginNextDir.Remove) | |
| plugin := "registry:5000/plugin-content-trust-upgrade" | |
| icmd.RunCommand("docker", "plugin", "create", plugin+":latest", pluginLatestDir.Path()).Assert(t, icmd.Success) | |
| icmd.RunCommand("docker", "plugin", "create", plugin+":next", pluginNextDir.Path()).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":latest"), defaultCmdOpts...).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":next"), defaultCmdOpts...).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin+":latest"), defaultCmdOpts...).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin+":next"), defaultCmdOpts...).Assert(t, icmd.Success) | |
| icmd.RunCmd(icmd.Command("docker", "plugin", "install", "--disable", "--grant-all-permissions", plugin+":latest"), defaultCmdOpts...).Assert(t, icmd.Success) | |
| return icmd.Command("docker", "plugin", "upgrade", plugin+":latest", plugin+":next") | |
| }, | |
| }, |
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.
Oh! And now curious; wouldn't that be something we could take advantage of? If we're building (and pushing) the exact same plugin multiple times; would we be able to use that so that we don't have to? 🤔
Wondering now; ISTR we have something similar in moby/moby, where we need to have an image that's built and pushed in CI (but have something to verify if it needs to be built / built only once). I'd have to go look for that though 🙈
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.
Not necessarily since there is also a test that verifies if it can push the plugin. Although optimization on if the plugin exists or not could be done, I didn't want to scope creep standardizing the plugin setup code for very small gains.
https://github.com/docker/cli/blob/master/e2e/plugin/trust_test.go#L37-L46
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.
Yes, definitely fine to look at separately
I agree that the As for default message and default accepted value ( |
Signed-off-by: Alano Terblanche <[email protected]>
66e73bc to
910d5d0
Compare
|
Re:
I support this, but quick reminder that as we learned with changing signal handling for plugins, these things aren't easy to get right – and we ended up reverting some of the changes/only setting up our own signal handling for plugins when the CLI isn't attached to a terminal. I think we should have some general |
thaJeztah
left a comment
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, thanks!

Follow up to #4888
This PR standardizes the commands return value that use
PromptForConfirmationand verifies the exit code to be 0 on prompt termination.- What I did
Add e2e tests, update command prompt termination tests and adjust error type returned from
PromptForConfirmationfunction.- How I did it
- How to verify it
- Description for the changelog
Standardize the exit code to
0for cancelling a confirmation prompt with SIGINT.- A picture of a cute animal (not mandatory but encouraged)
