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

Function TestQuitQuitQuitWithErrors

cmd/root_test.go:1550–1578  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1548}
1549
1550func TestQuitQuitQuitWithErrors(t *testing.T) {
1551 c := NewCommand(WithDialer(&errorDialer{}))
1552 c.SilenceUsage = true
1553 c.SilenceErrors = true
1554 c.SetArgs([]string{
1555 "--quitquitquit", "--admin-port", "9193",
1556 "my-project:my-region:my-instance",
1557 })
1558 ctx, cancel := context.WithCancel(context.Background())
1559 defer cancel()
1560
1561 errCh := make(chan error)
1562 go func() {
1563 err := c.ExecuteContext(ctx)
1564 errCh <- err
1565 }()
1566 resp, err := tryDial("POST", "http://localhost:9193/quitquitquit")
1567 if err != nil {
1568 t.Fatalf("failed to dial endpoint: %v", err)
1569 }
1570 if resp.StatusCode != http.StatusOK {
1571 t.Fatalf("expected a 200 status, got = %v", resp.StatusCode)
1572 }
1573 // The returned error is the error from closing the dialer.
1574 got := <-errCh
1575 if !strings.Contains(got.Error(), "close failed") {
1576 t.Fatalf("want = %v, got = %v", errCloseFailed, got)
1577 }
1578}

Callers

nothing calls this directly

Calls 4

NewCommandFunction · 0.85
WithDialerFunction · 0.85
tryDialFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected