MCPcopy Index your code
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / proxyConnTestWithReady

Function proxyConnTestWithReady

tests/connection_test.go:72–99  ·  view source on GitHub ↗
(t *testing.T, args []string, driver, dsn string, ready func() error)

Source from the content-addressed store, hash-verified

70 return string(creds)
71}
72func proxyConnTestWithReady(t *testing.T, args []string, driver, dsn string, ready func() error) {
73 ctx, cancel := context.WithTimeout(context.Background(), connTestTimeout)
74 defer cancel()
75 // Start the proxy
76 p, err := StartProxy(ctx, args...)
77 if err != nil {
78 t.Fatalf("unable to start proxy: %v", err)
79 }
80 defer p.Close()
81 output, err := p.WaitForServe(ctx)
82 if err != nil {
83 t.Fatalf("unable to verify proxy was serving: %s \n %s", err, output)
84 }
85 if err := ready(); err != nil {
86 t.Fatalf("proxy was not ready: %v", err)
87 }
88
89 // Connect to the instance
90 db, err := sql.Open(driver, dsn)
91 if err != nil {
92 t.Fatalf("unable to connect to db: %s", err)
93 }
94 defer db.Close()
95 _, err = db.Exec("SELECT 1;")
96 if err != nil {
97 t.Fatalf("unable to exec on db: %s", err)
98 }
99}
100
101// proxyConnTest is a test helper to verify the proxy works with a basic connectivity test.
102func proxyConnTest(t *testing.T, args []string, driver, dsn string) {

Callers 2

testFUSEFunction · 0.85
proxyConnTestFunction · 0.85

Calls 4

StartProxyFunction · 0.85
WaitForServeMethod · 0.80
OpenMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected