|
| 1 | +package helpdocs |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_helpFileName(t *testing.T) { |
| 11 | + assert.Equal(t, "container-test.md", helpFileName([]string{"container", "test"})) |
| 12 | + assert.Equal(t, "iac-describe.md", helpFileName([]string{"iac", "describe"})) |
| 13 | + assert.Equal(t, "secrets-test.md", helpFileName([]string{"secrets", "test"})) |
| 14 | +} |
| 15 | + |
| 16 | +func Test_HasUserDoc(t *testing.T) { |
| 17 | + help := CommandHelpForTest(t) |
| 18 | + |
| 19 | + tests := map[string]struct { |
| 20 | + segments []string |
| 21 | + want bool |
| 22 | + }{ |
| 23 | + "empty uses readme path": {segments: []string{}, want: true}, |
| 24 | + "test command": {segments: []string{"test"}, want: true}, |
| 25 | + "container test subcommand": {segments: []string{"container", "test"}, want: true}, |
| 26 | + "iac describe subcommand": {segments: []string{"iac", "describe"}, want: true}, |
| 27 | + "unknown command": {segments: []string{"rainmaker"}, want: false}, |
| 28 | + "undocumented secrets test": {segments: []string{"secrets", "test"}, want: false}, |
| 29 | + "redteam setup walks back to parent": {segments: []string{"redteam", "setup"}, want: true}, |
| 30 | + "undocumented agent-scan": {segments: []string{"agent-scan"}, want: false}, |
| 31 | + } |
| 32 | + |
| 33 | + for name, tc := range tests { |
| 34 | + t.Run(name, func(t *testing.T) { |
| 35 | + assert.Equal(t, tc.want, help.HasUserDoc(tc.segments)) |
| 36 | + }) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func Test_NewCommandHelpFromFS(t *testing.T) { |
| 41 | + expected := FixtureCommandHelp() |
| 42 | + |
| 43 | + help, err := NewCommandHelp(fixtureCommandHelpFS(), ".") |
| 44 | + require.NoError(t, err) |
| 45 | + |
| 46 | + for _, segments := range [][]string{ |
| 47 | + {"test"}, |
| 48 | + {"container", "test"}, |
| 49 | + {"rainmaker"}, |
| 50 | + } { |
| 51 | + assert.Equal(t, expected.HasUserDoc(segments), help.HasUserDoc(segments), segments) |
| 52 | + } |
| 53 | +} |
0 commit comments