(t *testing.T)
| 1503 | } |
| 1504 | |
| 1505 | func TestQuitQuitQuitHTTPGet(t *testing.T) { |
| 1506 | c := NewCommand(WithDialer(&spyDialer{})) |
| 1507 | c.SilenceUsage = true |
| 1508 | c.SilenceErrors = true |
| 1509 | c.SetArgs([]string{"--quitquitquit", "--admin-port", "9194", "my-project:my-region:my-instance"}) |
| 1510 | ctx, cancel := context.WithCancel(context.Background()) |
| 1511 | defer cancel() |
| 1512 | |
| 1513 | errCh := make(chan error) |
| 1514 | go func() { |
| 1515 | err := c.ExecuteContext(ctx) |
| 1516 | errCh <- err |
| 1517 | }() |
| 1518 | |
| 1519 | resp, err := tryDial("GET", "http://localhost:9194/quitquitquit") |
| 1520 | if err != nil { |
| 1521 | t.Fatalf("failed to dial endpoint: %v", err) |
| 1522 | } |
| 1523 | if resp.StatusCode != http.StatusOK { |
| 1524 | t.Fatalf("expected a 200 status, got = %v", resp.StatusCode) |
| 1525 | } |
| 1526 | |
| 1527 | var gotErr error |
| 1528 | select { |
| 1529 | case err := <-errCh: |
| 1530 | gotErr = err |
| 1531 | case <-time.After(30 * time.Second): |
| 1532 | t.Fatal("timeout waiting for error") |
| 1533 | } |
| 1534 | |
| 1535 | if !errors.Is(gotErr, errQuitQuitQuit) { |
| 1536 | t.Fatalf("want = %v, got = %v", errQuitQuitQuit, gotErr) |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | type errorDialer struct { |
| 1541 | spyDialer |
nothing calls this directly
no test coverage detected