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

Function StartProxy

tests/common_test.go:57–85  ·  view source on GitHub ↗

StartProxy returns a proxyExec representing a running instance of the proxy.

(ctx context.Context, args ...string)

Source from the content-addressed store, hash-verified

55
56// StartProxy returns a proxyExec representing a running instance of the proxy.
57func StartProxy(ctx context.Context, args ...string) (*ProxyExec, error) {
58 ctx, cancel := context.WithCancel(ctx)
59 // Open a pipe for tracking the output from the cmd
60 pr, pw, err := os.Pipe()
61 if err != nil {
62 cancel()
63 return nil, fmt.Errorf("unable to open stdout pipe: %w", err)
64 }
65
66 c := cmd.NewCommand(cmd.WithLogger(log.NewStdLogger(pw, pw)))
67 c.SetArgs(args)
68 c.SetOut(pw)
69 c.SetErr(pw)
70
71 p := &ProxyExec{
72 Out: pr,
73 cmd: c,
74 cancel: cancel,
75 closers: []io.Closer{pr, pw},
76 done: make(chan bool),
77 }
78 // Start the command in the background
79 go func() {
80 defer close(p.done)
81 defer cancel()
82 p.err = c.ExecuteContext(ctx)
83 }()
84 return p, nil
85}
86
87// Stop sends the TERM signal to the proxy and returns.
88func (p *ProxyExec) Stop() {

Callers 3

TestVersionFunction · 0.85
proxyConnTestWithReadyFunction · 0.85
testHealthCheckFunction · 0.85

Calls 4

NewCommandFunction · 0.92
WithLoggerFunction · 0.92
NewStdLoggerFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected