(t *testing.T)
| 165 | } |
| 166 | |
| 167 | func TestCommandOptionsOverridesCLI(t *testing.T) { |
| 168 | tcs := []struct { |
| 169 | desc string |
| 170 | isValid func(*Command) error |
| 171 | option Option |
| 172 | args []string |
| 173 | }{ |
| 174 | { |
| 175 | desc: "with duplicate max connections", |
| 176 | isValid: func(c *Command) error { |
| 177 | if c.conf.MaxConnections != 10 { |
| 178 | return errors.New("max connections do not match") |
| 179 | } |
| 180 | return nil |
| 181 | }, |
| 182 | option: WithMaxConnections(10), |
| 183 | args: []string{"--max-connections", "20"}, |
| 184 | }, |
| 185 | { |
| 186 | desc: "with quiet logging", |
| 187 | isValid: func(c *Command) error { |
| 188 | if !c.conf.Quiet { |
| 189 | return errors.New("quiet was false, but should be true") |
| 190 | } |
| 191 | return nil |
| 192 | }, |
| 193 | option: WithQuietLogging(), |
| 194 | args: []string{"--quiet", "false"}, |
| 195 | }, |
| 196 | } |
| 197 | for _, tc := range tcs { |
| 198 | t.Run(tc.desc, func(t *testing.T) { |
| 199 | got, err := invokeProxyWithOption(tc.args, tc.option) |
| 200 | if err != nil { |
| 201 | t.Fatal(err) |
| 202 | } |
| 203 | if err := tc.isValid(got); err != nil { |
| 204 | t.Errorf("option did not initialize command correctly: %v", err) |
| 205 | } |
| 206 | }) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | func invokeProxyWithOption(args []string, o Option) (*Command, error) { |
| 211 | c := NewCommand(o) |
nothing calls this directly
no test coverage detected