Fix help message flags on docker stack commands and sub-commands#1251
Conversation
PersistentPreRunE needs to be called within the help function to initialize all the flags (notably the orchestrator flag) Add an e2e test as regression test Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Codecov Report
@@ Coverage Diff @@
## master #1251 +/- ##
==========================================
- Coverage 54.23% 54.21% -0.02%
==========================================
Files 268 268
Lines 17809 17814 +5
==========================================
Hits 9658 9658
- Misses 7543 7548 +5
Partials 608 608 |
| func testStackDeployHelp(t *testing.T, orchestrator string) { | ||
| result := icmd.RunCommand("docker", "stack", "deploy", "--orchestrator", orchestrator, "--help") | ||
| result.Assert(t, icmd.Success) | ||
| golden.Assert(t, result.Stdout(), fmt.Sprintf("stack-deploy-help-%s.golden", orchestrator)) |
There was a problem hiding this comment.
Is this the commonly used way to verify command outputs in this project? This will break every time an option or help message is added/modified, this producing unnecessary maintenance work.
Alternatively, we could check for the presence of specific flags via substring checks.
There was a problem hiding this comment.
@albers I think it's safe to "break every time" on that command as we don't often change those, and if we do well, the test is easily fixable (go test -update or sthg like that). I do agree it's not ideal though, but 😅
albers
left a comment
There was a problem hiding this comment.
Works perfectly, thanks a lot.
|
There is also a problem in # DOCKER_STACK_ORCHESTRATOR=swarm docker version --help | grep kubeconfig
--kubeconfig string Kubernetes config file
# DOCKER_STACK_ORCHESTRATOR=kubernetes docker version --help | grep kubeconfig
--kubeconfig string Kubernetes config file
# docker --version
Docker version 18.09.0-dev, build 21cce52b |
| func testStackDeployHelp(t *testing.T, orchestrator string) { | ||
| result := icmd.RunCommand("docker", "stack", "deploy", "--orchestrator", orchestrator, "--help") | ||
| result.Assert(t, icmd.Success) | ||
| golden.Assert(t, result.Stdout(), fmt.Sprintf("stack-deploy-help-%s.golden", orchestrator)) |
There was a problem hiding this comment.
@albers I think it's safe to "break every time" on that command as we don't often change those, and if we do well, the test is easily fixable (go test -update or sthg like that). I do agree it's not ideal though, but 😅
|
@albers I'll fix the |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM
was wondering if this should be a unit-test, but looks like that requires more rigging if we need the full output
|
Well the problem is that the root docker command does a lot of stuffs with the help command (formatting included), so testing at the stack command level won't really help testing the final feature. |
@silvin-lubecki I created #1265 as a reminder. |
- What I did
Fix issue #1243
Add an e2e test as regression test
- How I did it
PersistentPreRunE needs to be called within the help function to initialize all the flags (notably the orchestrator flag)
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)

Lots of kudos for @albers !!