| 8 | ) |
| 9 | |
| 10 | func TestCmdHelpTopic(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | topic helpTopic |
| 16 | args []string |
| 17 | flags []string |
| 18 | errorAssertion require.ErrorAssertionFunc |
| 19 | expectedAnnotations map[string]string |
| 20 | }{ |
| 21 | { |
| 22 | name: "when there are no args or flags, prints the long message to stdout", |
| 23 | topic: helpTopic{name: "test-topic", long: "test-topic-long"}, |
| 24 | args: []string{}, |
| 25 | flags: []string{}, |
| 26 | errorAssertion: require.NoError, |
| 27 | }, |
| 28 | { |
| 29 | name: "when an arg is provided, it is ignored and help is printed", |
| 30 | topic: helpTopic{name: "test-topic"}, |
| 31 | args: []string{"anything"}, |
| 32 | flags: []string{}, |
| 33 | errorAssertion: require.NoError, |
| 34 | }, |
| 35 | { |
| 36 | name: "when a flag is provided, returns an error", |
| 37 | topic: helpTopic{name: "test-topic"}, |
| 38 | args: []string{}, |
| 39 | flags: []string{"--anything"}, |
| 40 | errorAssertion: require.Error, |
| 41 | }, |
| 42 | { |
| 43 | name: "when there is an example, include it in the stdout", |
| 44 | topic: helpTopic{name: "test-topic", example: "test-topic-example"}, |
| 45 | args: []string{}, |
| 46 | flags: []string{}, |
| 47 | errorAssertion: require.NoError, |
| 48 | }, |
| 49 | { |
| 50 | name: "sets important markdown annotations on the command", |
| 51 | topic: helpTopic{name: "test-topic"}, |
| 52 | args: []string{}, |
| 53 | flags: []string{}, |
| 54 | errorAssertion: require.NoError, |
| 55 | expectedAnnotations: map[string]string{ |
| 56 | "markdown:generate": "true", |
| 57 | "markdown:basename": "gh_help_test-topic", |
| 58 | }, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | for _, tt := range tests { |
| 63 | t.Run(tt.name, func(t *testing.T) { |
| 64 | t.Parallel() |
| 65 | |
| 66 | ios, _, stdout, _ := iostreams.Test() |
| 67 | |