func (p *FakeContainerPool) Create(spec warden.ContainerSpec) (linux_backend.Container, error) { if p.CreateError != nil { return nil, p.CreateError } container := fake_backend.NewFakeContainer(spec) if p.ContainerSetup != nil { p.ContainerSetup(container) } p.CreatedContainers = append(p.CreatedContainers, container) return container, nil }
func (p *FakeContainerPool) Restore(snapshot io.Reader) (linux_backend.Container, error) { if p.RestoreError != nil { return nil, p.RestoreError } var handle string _, err := fmt.Fscanf(snapshot, "%s", &handle) if err != nil && err != io.EOF { return nil, err } container := fake_backend.NewFakeContainer( warden.ContainerSpec{ Handle: handle, }, ) p.RestoredSnapshots = append(p.RestoredSnapshots, snapshot) return container, nil }
"github.com/cloudfoundry-incubator/garden/server/bomberman" "github.com/cloudfoundry-incubator/garden/warden" "github.com/cloudfoundry-incubator/garden/warden/fake_backend" ) var _ = Describe("Bomberman", func() { It("straps a bomb to the given container with the container's grace time as the countdown", func() { detonated := make(chan warden.Container) bomberman := bomberman.New(fake_backend.New(), func(container warden.Container) { detonated <- container }) container := fake_backend.NewFakeContainer( warden.ContainerSpec{ GraceTime: 100 * time.Millisecond, Handle: "doomed", }, ) bomberman.Strap(container) select { case <-detonated: case <-time.After(container.GraceTime() + 50*time.Millisecond): Fail("did not detonate!") } }) Context("when the container has a grace time of 0", func() { It("never detonates", func() { detonated := make(chan warden.Container)