waitForCVM waits for the inner container to spin up.
(t *testing.T, pool *dockertest.Pool, resource *dockertest.Resource)
| 211 | |
| 212 | // waitForCVM waits for the inner container to spin up. |
| 213 | func waitForCVM(t *testing.T, pool *dockertest.Pool, resource *dockertest.Resource) bool { |
| 214 | t.Helper() |
| 215 | |
| 216 | rd, wr := io.Pipe() |
| 217 | defer rd.Close() |
| 218 | defer wr.Close() |
| 219 | ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) |
| 220 | defer cancel() |
| 221 | go func() { |
| 222 | defer wr.Close() |
| 223 | err := pool.Client.Logs(docker.LogsOptions{ |
| 224 | Context: ctx, |
| 225 | Container: resource.Container.ID, |
| 226 | OutputStream: wr, |
| 227 | ErrorStream: wr, |
| 228 | Follow: true, |
| 229 | Stdout: true, |
| 230 | Stderr: true, |
| 231 | }) |
| 232 | if ctx.Err() == nil { |
| 233 | // Only check if error is nil if we didn't cancel the context. |
| 234 | require.NoError(t, err) |
| 235 | } |
| 236 | }() |
| 237 | |
| 238 | scanner := bufio.NewScanner(rd) |
| 239 | var finished bool |
| 240 | for scanner.Scan() { |
| 241 | log := scanner.Text() |
| 242 | |
| 243 | t.Log(log) |
| 244 | var blog buildlog.JSONLog |
| 245 | if err := json.Unmarshal([]byte(log), &blog); err != nil { |
| 246 | continue |
| 247 | } |
| 248 | |
| 249 | if blog.Type == buildlog.JSONLogTypeDone { |
| 250 | finished = true |
| 251 | break |
| 252 | } |
| 253 | |
| 254 | if blog.Type == buildlog.JSONLogTypeError { |
| 255 | t.Logf("envbox failed (%s)", blog.Output) |
| 256 | return false |
| 257 | } |
| 258 | } |
| 259 | require.NoError(t, scanner.Err()) |
| 260 | require.True(t, finished, "unexpected logger exit") |
| 261 | return true |
| 262 | } |
| 263 | |
| 264 | type ExecConfig struct { |
| 265 | ContainerID string |