(t *testing.T)
| 2622 | } |
| 2623 | |
| 2624 | func TestCommand_Run_Help(t *testing.T) { |
| 2625 | tests := []struct { |
| 2626 | helpArguments []string |
| 2627 | hideHelp bool |
| 2628 | wantContains string |
| 2629 | wantErr error |
| 2630 | }{ |
| 2631 | { |
| 2632 | helpArguments: []string{"boom", "--help"}, |
| 2633 | hideHelp: false, |
| 2634 | wantContains: "boom - make an explosive entrance", |
| 2635 | }, |
| 2636 | { |
| 2637 | helpArguments: []string{"boom", "-h"}, |
| 2638 | hideHelp: false, |
| 2639 | wantContains: "boom - make an explosive entrance", |
| 2640 | }, |
| 2641 | { |
| 2642 | helpArguments: []string{"boom", "help"}, |
| 2643 | hideHelp: false, |
| 2644 | wantContains: "boom - make an explosive entrance", |
| 2645 | }, |
| 2646 | { |
| 2647 | helpArguments: []string{"boom", "--help"}, |
| 2648 | hideHelp: true, |
| 2649 | wantErr: fmt.Errorf("flag provided but not defined: -help"), |
| 2650 | }, |
| 2651 | { |
| 2652 | helpArguments: []string{"boom", "-h"}, |
| 2653 | hideHelp: true, |
| 2654 | wantErr: fmt.Errorf("flag provided but not defined: -h"), |
| 2655 | }, |
| 2656 | { |
| 2657 | helpArguments: []string{"boom", "help"}, |
| 2658 | hideHelp: true, |
| 2659 | wantContains: "boom I say!", |
| 2660 | }, |
| 2661 | } |
| 2662 | |
| 2663 | for _, tt := range tests { |
| 2664 | t.Run(fmt.Sprintf("checking with arguments %v%v", tt.helpArguments, tt.hideHelp), func(t *testing.T) { |
| 2665 | buf := new(bytes.Buffer) |
| 2666 | |
| 2667 | cmd := &Command{ |
| 2668 | Name: "boom", |
| 2669 | Usage: "make an explosive entrance", |
| 2670 | Writer: buf, |
| 2671 | HideHelp: tt.hideHelp, |
| 2672 | Action: func(context.Context, *Command) error { |
| 2673 | buf.WriteString("boom I say!") |
| 2674 | return nil |
| 2675 | }, |
| 2676 | } |
| 2677 | |
| 2678 | err := cmd.Run(buildTestContext(t), tt.helpArguments) |
| 2679 | if tt.wantErr != nil { |
| 2680 | assert.ErrorContains(t, err, tt.wantErr.Error()) |
| 2681 | } |
nothing calls this directly
no test coverage detected