TestGlobalHelp ensures correct behaviour when running `docker help`
(t *testing.T)
| 11 | |
| 12 | // TestGlobalHelp ensures correct behaviour when running `docker help` |
| 13 | func TestGlobalHelp(t *testing.T) { |
| 14 | run, _, cleanup := prepare(t) |
| 15 | defer cleanup() |
| 16 | |
| 17 | res := icmd.RunCmd(run("help")) |
| 18 | res.Assert(t, icmd.Expected{ |
| 19 | ExitCode: 0, |
| 20 | }) |
| 21 | assert.Assert(t, is.Equal(res.Stderr(), "")) |
| 22 | output := res.Stdout() |
| 23 | |
| 24 | // Instead of baking in the full current output of `docker |
| 25 | // help`, which can be expected to change regularly, bake in |
| 26 | // some checkpoints. Key things we are looking for: |
| 27 | // |
| 28 | // - The top-level description |
| 29 | // - Each of the main headings |
| 30 | // - Some builtin commands under the main headings |
| 31 | // - The `helloworld` plugin in the appropriate place |
| 32 | // - The `badmeta` plugin under the "Invalid Plugins" heading. |
| 33 | // |
| 34 | // Regexps are needed because the width depends on `unix.TIOCGWINSZ` or similar. |
| 35 | for _, s := range []string{ |
| 36 | `Management Commands:`, |
| 37 | `\s+container\s+Manage containers`, |
| 38 | `\s+helloworld\*\s+A basic Hello World plugin for tests`, |
| 39 | `\s+image\s+Manage images`, |
| 40 | `Commands:`, |
| 41 | `\s+create\s+Create a new container`, |
| 42 | `Invalid Plugins:`, |
| 43 | `\s+badmeta\s+invalid metadata: invalid character 'i' looking for beginning of object key string`, |
| 44 | } { |
| 45 | expected, err := regexp.Compile(`(?m)^` + s + `$`) |
| 46 | assert.NilError(t, err) |
| 47 | matches := expected.FindAllString(output, -1) |
| 48 | assert.Equal(t, len(matches), 1, "Did not find expected number of matches for %q in `docker help` output", expected) |
| 49 | } |
| 50 | |
| 51 | // Running with `--help` should produce the same. |
| 52 | t.Run("help_flag", func(t *testing.T) { |
| 53 | res2 := icmd.RunCmd(run("--help")) |
| 54 | res2.Assert(t, icmd.Expected{ |
| 55 | ExitCode: 0, |
| 56 | }) |
| 57 | assert.Assert(t, is.Equal(res2.Stdout(), output)) |
| 58 | assert.Assert(t, is.Equal(res2.Stderr(), "")) |
| 59 | }) |
| 60 | |
| 61 | // Running just `docker` (without `help` nor `--help`) should produce the same thing, except on Stderr. |
| 62 | t.Run("bare", func(t *testing.T) { |
| 63 | res2 := icmd.RunCmd(run()) |
| 64 | res2.Assert(t, icmd.Expected{ |
| 65 | ExitCode: 0, |
| 66 | }) |
| 67 | assert.Assert(t, is.Equal(res2.Stdout(), "")) |
| 68 | assert.Assert(t, is.Equal(res2.Stderr(), output)) |
| 69 | }) |
| 70 |
nothing calls this directly
no test coverage detected
searching dependent graphs…