RequireServiceState ensures that the container is in the expected state (running or exited).
(t testing.TB, cli *CLI, service string, state string)
| 28 | // RequireServiceState ensures that the container is in the expected state |
| 29 | // (running or exited). |
| 30 | func RequireServiceState(t testing.TB, cli *CLI, service string, state string) { |
| 31 | t.Helper() |
| 32 | psRes := cli.RunDockerComposeCmd(t, "ps", "--all", "--format=json", service) |
| 33 | var svc map[string]any |
| 34 | assert.NilError(t, json.Unmarshal([]byte(psRes.Stdout()), &svc), |
| 35 | "Invalid `compose ps` JSON: command output: %s", |
| 36 | psRes.Combined()) |
| 37 | |
| 38 | assert.Assert(t, is.Equal(service, svc["Service"]), "Found ps output for unexpected service") |
| 39 | assert.Assert(t, is.Equal(strings.ToLower(state), strings.ToLower(svc["State"].(string))), |
| 40 | "Service %q (%s) not in expected state", |
| 41 | service, svc["Name"], |
| 42 | ) |
| 43 | } |
searching dependent graphs…