MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestCommandOptionsOverridesCLI

Function TestCommandOptionsOverridesCLI

cmd/options_test.go:167–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

165}
166
167func 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
210func invokeProxyWithOption(args []string, o Option) (*Command, error) {
211 c := NewCommand(o)

Callers

nothing calls this directly

Calls 4

WithMaxConnectionsFunction · 0.85
WithQuietLoggingFunction · 0.85
invokeProxyWithOptionFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected