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

Function newTestClient

internal/proxy/fuse_test.go:45–77  ·  view source on GitHub ↗

newTestClient is a convenience function for testing that creates a proxy.Client and starts it. The returned cleanup function is also a convenience. Callers may choose to ignore it and manually close the client.

(t *testing.T, d cloudsql.Dialer, fuseDir, fuseTempDir string)

Source from the content-addressed store, hash-verified

43// proxy.Client and starts it. The returned cleanup function is also a
44// convenience. Callers may choose to ignore it and manually close the client.
45func newTestClient(t *testing.T, d cloudsql.Dialer, fuseDir, fuseTempDir string) (*proxy.Client, chan error, func()) {
46 conf := &proxy.Config{FUSEDir: fuseDir, FUSETempDir: fuseTempDir}
47
48 // This context is only used to call the Cloud SQL API
49 c, err := proxy.NewClient(context.Background(), d, testLogger, conf, nil)
50 if err != nil {
51 t.Fatalf("want error = nil, got = %v", err)
52 }
53
54 ready := make(chan struct{})
55 servErrCh := make(chan error)
56
57 ctx, cancel := context.WithCancel(context.Background())
58 go func() {
59
60 servErr := c.Serve(ctx, func() { close(ready) })
61 select {
62 case servErrCh <- servErr:
63 case <-ctx.Done():
64 }
65 }()
66 select {
67 case <-ready:
68 case <-time.Tick(5 * time.Second):
69 t.Fatal("failed to Serve")
70 }
71 return c, servErrCh, func() {
72 if cErr := c.Close(); cErr != nil {
73 t.Logf("failed to close client: %v", cErr)
74 }
75 cancel()
76 }
77}
78
79func TestFUSEREADME(t *testing.T) {
80 if testing.Short() {

Callers 9

TestFUSEREADMEFunction · 0.85
TestFUSEDialInstanceFunction · 0.85
TestFUSEReadDirFunction · 0.85
TestLookupIgnoresContextFunction · 0.85
TestFUSEErrorsFunction · 0.85
TestFUSECheckConnectionsFunction · 0.85
TestFUSECloseFunction · 0.85

Calls 4

ServeMethod · 0.95
CloseMethod · 0.95
NewClientFunction · 0.92
DoneMethod · 0.80

Tested by

no test coverage detected