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)
| 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. |
| 45 | func 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 | |
| 79 | func TestFUSEREADME(t *testing.T) { |
| 80 | if testing.Short() { |
no test coverage detected