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

Function TestShutdownCommand

cmd/shutdown_test.go:25–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func 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
58func TestShutdownCommandFails(t *testing.T) {
59 _, err := invokeProxyCommand([]string{

Callers

nothing calls this directly

Calls 5

invokeProxyCommandFunction · 0.85
StringMethod · 0.80
AddrMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected