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

Function TestQuitQuitQuitHTTPPost

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

Source from the content-addressed store, hash-verified

1462}
1463
1464func TestQuitQuitQuitHTTPPost(t *testing.T) {
1465 c := NewCommand(WithDialer(&spyDialer{}))
1466 c.SilenceUsage = true
1467 c.SilenceErrors = true
1468 c.SetArgs([]string{"--quitquitquit", "--admin-port", "9192", "my-project:my-region:my-instance"})
1469 ctx, cancel := context.WithCancel(context.Background())
1470 defer cancel()
1471
1472 errCh := make(chan error)
1473 go func() {
1474 err := c.ExecuteContext(ctx)
1475 errCh <- err
1476 }()
1477 resp, err := tryDial("HEAD", "http://localhost:9192/quitquitquit")
1478 if err != nil {
1479 t.Fatalf("failed to dial endpoint: %v", err)
1480 }
1481 if resp.StatusCode != http.StatusBadRequest {
1482 t.Fatalf("expected a 400 status, got = %v", resp.StatusCode)
1483 }
1484 resp, err = tryDial("POST", "http://localhost:9192/quitquitquit")
1485 if err != nil {
1486 t.Fatalf("failed to dial endpoint: %v", err)
1487 }
1488 if resp.StatusCode != http.StatusOK {
1489 t.Fatalf("expected a 200 status, got = %v", resp.StatusCode)
1490 }
1491
1492 var gotErr error
1493 select {
1494 case err := <-errCh:
1495 gotErr = err
1496 case <-time.After(30 * time.Second):
1497 t.Fatal("timeout waiting for error")
1498 }
1499
1500 if !errors.Is(gotErr, errQuitQuitQuit) {
1501 t.Fatalf("want = %v, got = %v", errQuitQuitQuit, gotErr)
1502 }
1503}
1504
1505func TestQuitQuitQuitHTTPGet(t *testing.T) {
1506 c := NewCommand(WithDialer(&spyDialer{}))

Callers

nothing calls this directly

Calls 3

NewCommandFunction · 0.85
WithDialerFunction · 0.85
tryDialFunction · 0.85

Tested by

no test coverage detected