(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func Test_IsAuthCheckEnabled(t *testing.T) { |
| 60 | tests := []struct { |
| 61 | name string |
| 62 | init func() (*cobra.Command, error) |
| 63 | isAuthCheckEnabled bool |
| 64 | }{ |
| 65 | { |
| 66 | name: "no annotations", |
| 67 | init: func() (*cobra.Command, error) { |
| 68 | cmd := &cobra.Command{} |
| 69 | cmd.Flags().Bool("flag", false, "") |
| 70 | return cmd, nil |
| 71 | }, |
| 72 | isAuthCheckEnabled: true, |
| 73 | }, |
| 74 | { |
| 75 | name: "command-level disable", |
| 76 | init: func() (*cobra.Command, error) { |
| 77 | cmd := &cobra.Command{} |
| 78 | DisableAuthCheck(cmd) |
| 79 | return cmd, nil |
| 80 | }, |
| 81 | isAuthCheckEnabled: false, |
| 82 | }, |
| 83 | { |
| 84 | name: "command with flag-level disable, flag not set", |
| 85 | init: func() (*cobra.Command, error) { |
| 86 | cmd := &cobra.Command{} |
| 87 | cmd.Flags().Bool("flag", false, "") |
| 88 | DisableAuthCheckFlag(cmd.Flag("flag")) |
| 89 | return cmd, nil |
| 90 | }, |
| 91 | isAuthCheckEnabled: true, |
| 92 | }, |
| 93 | { |
| 94 | name: "command with flag-level disable, flag set", |
| 95 | init: func() (*cobra.Command, error) { |
| 96 | cmd := &cobra.Command{} |
| 97 | cmd.Flags().Bool("flag", false, "") |
| 98 | if err := cmd.Flags().Set("flag", "true"); err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | DisableAuthCheckFlag(cmd.Flag("flag")) |
| 103 | return cmd, nil |
| 104 | }, |
| 105 | isAuthCheckEnabled: false, |
| 106 | }, |
| 107 | } |
| 108 | |
| 109 | for _, tt := range tests { |
| 110 | t.Run(tt.name, func(t *testing.T) { |
| 111 | cmd, err := tt.init() |
| 112 | require.NoError(t, err) |
| 113 | |
| 114 | // IsAuthCheckEnabled assumes commands under test are subcommands |
| 115 | parent := &cobra.Command{Use: "root"} |
| 116 | parent.AddCommand(cmd) |
nothing calls this directly
no test coverage detected