(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestAddJSONFlagsWithoutShorthand(t *testing.T) { |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | setFlags func(cmd *cobra.Command) |
| 126 | wantFlags map[string]string |
| 127 | }{ |
| 128 | { |
| 129 | name: "no conflicting flags", |
| 130 | setFlags: func(cmd *cobra.Command) { |
| 131 | cmd.Flags().StringP("web", "w", "", "") |
| 132 | cmd.Flags().StringP("token", "t", "", "") |
| 133 | }, |
| 134 | wantFlags: map[string]string{ |
| 135 | "web": "w", |
| 136 | "token": "t", |
| 137 | "jq": "", |
| 138 | "template": "", |
| 139 | "json": "", |
| 140 | }, |
| 141 | }, |
| 142 | } |
| 143 | for _, tt := range tests { |
| 144 | t.Run(tt.name, func(t *testing.T) { |
| 145 | |
| 146 | cmd := &cobra.Command{Run: func(*cobra.Command, []string) {}} |
| 147 | tt.setFlags(cmd) |
| 148 | |
| 149 | AddJSONFlagsWithoutShorthand(cmd, nil, []string{}) |
| 150 | |
| 151 | for f, shorthand := range tt.wantFlags { |
| 152 | flag := cmd.Flags().Lookup(f) |
| 153 | require.NotNil(t, flag) |
| 154 | require.Equal(t, shorthand, flag.Shorthand) |
| 155 | } |
| 156 | }) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // TestAddJSONFlagsSetsAnnotations asserts that `AddJSONFlags` function adds the |
| 161 | // appropriate annotation to the command, which could later be used by doc |
nothing calls this directly
no test coverage detected