(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestShutdownCommand(t *testing.T) { |
| 26 | shutdownCh := make(chan bool, 1) |
| 27 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 28 | if r.Method != "POST" { |
| 29 | t.Errorf("want = POST, got = %v", r.Method) |
| 30 | } |
| 31 | w.WriteHeader(http.StatusOK) |
| 32 | shutdownCh <- true |
| 33 | } |
| 34 | server := httptest.NewServer(http.HandlerFunc(handler)) |
| 35 | defer server.Close() |
| 36 | |
| 37 | _, port, err := net.SplitHostPort(server.Listener.Addr().String()) |
| 38 | if err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | |
| 42 | _, err = invokeProxyCommand([]string{ |
| 43 | "shutdown", |
| 44 | "--admin-port", port, |
| 45 | }) |
| 46 | if err != nil { |
| 47 | t.Fatalf("invokeProxyCommand failed: %v", err) |
| 48 | } |
| 49 | |
| 50 | select { |
| 51 | case <-shutdownCh: |
| 52 | // success |
| 53 | case <-time.After(1 * time.Second): |
| 54 | t.Fatal("server did not receive shutdown request") |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestShutdownCommandFails(t *testing.T) { |
| 59 | _, err := invokeProxyCommand([]string{ |
nothing calls this directly
no test coverage detected