WaitForServe waits until the proxy ready to serve traffic by waiting for a known log message (i.e. "ready for new connections"). Returns any output from the proxy while starting or any errors experienced before the proxy was ready to server.
(ctx context.Context)
| 122 | // from the proxy while starting or any errors experienced before the proxy was |
| 123 | // ready to server. |
| 124 | func (p *ProxyExec) WaitForServe(ctx context.Context) (string, error) { |
| 125 | in := bufio.NewReader(p.Out) |
| 126 | for { |
| 127 | select { |
| 128 | case <-ctx.Done(): |
| 129 | // dump all output and return it as an error |
| 130 | all, err := io.ReadAll(in) |
| 131 | if err != nil { |
| 132 | return "", err |
| 133 | } |
| 134 | return "", errors.New(string(all)) |
| 135 | default: |
| 136 | } |
| 137 | s, err := in.ReadString('\n') |
| 138 | if err != nil { |
| 139 | return "", err |
| 140 | } |
| 141 | if strings.Contains(s, "Error") || strings.Contains(s, "error") { |
| 142 | return "", errors.New(s) |
| 143 | } |
| 144 | if strings.Contains(s, "ready for new connections") { |
| 145 | return s, nil |
| 146 | } |
| 147 | } |
| 148 | } |
no test coverage detected