(t *testing.T)
| 212 | } |
| 213 | |
| 214 | func TestEmitRunningEvents(t *testing.T) { |
| 215 | runningWeb := ObservedContainer{ID: "c-web", Name: "p-web-1", State: container.StateRunning} |
| 216 | runningDB := ObservedContainer{ID: "c-db", Name: "p-db-1", State: container.StateRunning} |
| 217 | runningDisabled := ObservedContainer{ID: "c-misc", Name: "p-misc-1", State: container.StateRunning} |
| 218 | exitedWeb := ObservedContainer{ID: "c-web-old", Name: "p-web-2", State: container.StateExited} |
| 219 | |
| 220 | t.Run("emits Running for active services not in plan", func(t *testing.T) { |
| 221 | project := &types.Project{ |
| 222 | Services: types.Services{ |
| 223 | "web": {Name: "web"}, |
| 224 | "db": {Name: "db"}, |
| 225 | }, |
| 226 | } |
| 227 | observed := &ObservedState{ |
| 228 | Containers: map[string][]ObservedContainer{ |
| 229 | "web": {runningWeb}, |
| 230 | "db": {runningDB}, |
| 231 | }, |
| 232 | } |
| 233 | events := &capturingEvents{} |
| 234 | |
| 235 | emitRunningEvents(project, observed, &Plan{}, events) |
| 236 | |
| 237 | assert.Equal(t, len(events.resources), 2) |
| 238 | names := map[string]bool{} |
| 239 | for _, r := range events.resources { |
| 240 | names[r.ID] = true |
| 241 | assert.Equal(t, r.Text, api.StatusRunning) |
| 242 | } |
| 243 | assert.Assert(t, names["Container p-web-1"]) |
| 244 | assert.Assert(t, names["Container p-db-1"]) |
| 245 | }) |
| 246 | |
| 247 | t.Run("skips containers belonging to disabled services", func(t *testing.T) { |
| 248 | // Reproduces issue 13882: `compose run --no-deps misc` leaves the |
| 249 | // project with project.Services empty (misc moved to DisabledServices). |
| 250 | // Running containers for disabled services must not be reported. |
| 251 | project := &types.Project{ |
| 252 | Services: types.Services{}, |
| 253 | DisabledServices: types.Services{ |
| 254 | "misc": {Name: "misc"}, |
| 255 | "db": {Name: "db"}, |
| 256 | }, |
| 257 | } |
| 258 | observed := &ObservedState{ |
| 259 | Containers: map[string][]ObservedContainer{ |
| 260 | "misc": {runningDisabled}, |
| 261 | "db": {runningDB}, |
| 262 | }, |
| 263 | } |
| 264 | events := &capturingEvents{} |
| 265 | |
| 266 | emitRunningEvents(project, observed, &Plan{}, events) |
| 267 | |
| 268 | assert.Equal(t, len(events.resources), 0) |
| 269 | }) |
| 270 | |
| 271 | t.Run("skips containers that have a plan operation", func(t *testing.T) { |
nothing calls this directly
no test coverage detected