var container warden.Container BeforeEach(func() { var err error container, err = client.Create(warden.ContainerSpec{ Properties: warden.Properties{ "foo": "bar", "a": "b", }, }) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { err := client.Destroy(container.Handle()) Expect(err).ToNot(HaveOccurred()) }) Describe("when reporting the container's info", func() { It("includes the properties", func() { info, err := container.Info() Ω(err).ShouldNot(HaveOccurred()) Ω(info.Properties["foo"]).Should(Equal("bar")) Ω(info.Properties["a"]).Should(Equal("b")) Ω(info.Properties).Should(HaveLen(2)) }) })
atomic.AddUint64(&receivedBytes, uint64(len(res.Data))) } }(results) spawned <- true }() } for j := 0; j < numToSpawn; j++ { <-spawned } }) AfterEach(func() { err := client.Destroy(container.Handle()) Expect(err).ToNot(HaveOccurred()) }) Measure("it should not adversely affect the rest of the API", func(b Benchmarker) { var newContainer warden.Container b.Time("creating another container", func() { var err error newContainer, err = client.Create(warden.ContainerSpec{}) Expect(err).ToNot(HaveOccurred()) }) for i := 0; i < 10; i++ { b.Time("getting container info (10x)", func() {
func (s *WardenServer) reapContainer(container warden.Container) { log.Printf("reaping %s (idle for %s)\n", container.Handle(), s.backend.GraceTime(container)) s.backend.Destroy(container.Handle()) }
. "github.com/onsi/gomega" archiver "github.com/pivotal-golang/archiver/extractor/test_helper" ) var _ = Describe("Creating a container", func() { var container warden.Container BeforeEach(func() { var err error container, err = client.Create(warden.ContainerSpec{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { err := client.Destroy(container.Handle()) Expect(err).ToNot(HaveOccurred()) }) It("sources /etc/seed", func() { _, stream, err := container.Run(warden.ProcessSpec{ Script: "test -e /tmp/ran-seed", }) Expect(err).ToNot(HaveOccurred()) for chunk := range stream { if chunk.ExitStatus != nil { Expect(*chunk.ExitStatus).To(Equal(uint32(0))) } } })
BeforeEach(func() { fakeContainerPool = fake_container_pool.New() fakeSystemInfo := fake_system_info.NewFakeProvider() linuxBackend = linux_backend.New(fakeContainerPool, fakeSystemInfo, "") newContainer, err := linuxBackend.Create(warden.ContainerSpec{}) Expect(err).ToNot(HaveOccurred()) container = newContainer }) It("removes the given container from the pool", func() { Expect(fakeContainerPool.DestroyedContainers).To(BeEmpty()) err := linuxBackend.Destroy(container.Handle()) Expect(err).ToNot(HaveOccurred()) Expect(fakeContainerPool.DestroyedContainers).To(ContainElement(container)) }) It("unregisters the container", func() { err := linuxBackend.Destroy(container.Handle()) Expect(err).ToNot(HaveOccurred()) _, err = linuxBackend.Lookup(container.Handle()) Expect(err).To(HaveOccurred()) Expect(err).To(Equal(linux_backend.UnknownHandleError{container.Handle()})) }) Context("when the container does not exist", func() {
JustBeforeEach(func() { var err error client := New(connectionProvider) fakeConnection.WhenCreating = func(warden.ContainerSpec) (string, error) { return "some-handle", nil } container, err = client.Create(warden.ContainerSpec{}) Ω(err).ShouldNot(HaveOccurred()) }) Describe("Handle", func() { It("returns the container's handle", func() { Ω(container.Handle()).Should(Equal("some-handle")) }) }) Describe("Stop", func() { It("sends a stop request", func() { err := container.Stop(true) Ω(err).ShouldNot(HaveOccurred()) Ω(fakeConnection.Stopped("some-handle")).Should(ContainElement( fake_connection.StopSpec{ Background: false, Kill: true, }, )) })
runner.Stop() runner.Start( "-denyNetworks", strings.Join([]string{ blockedListenerIP + "/32", allowedListenerIP + "/32", }, ","), "-allowNetworks", allowedListenerIP+"/32", ) // create a container with the new deny network configuration sender, err = client.Create(warden.ContainerSpec{}) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { err := client.Destroy(sender.Handle()) Expect(err).ToNot(HaveOccurred()) err = client.Destroy(blockedListener.Handle()) Expect(err).ToNot(HaveOccurred()) err = client.Destroy(unblockedListener.Handle()) Expect(err).ToNot(HaveOccurred()) err = client.Destroy(allowedListener.Handle()) Expect(err).ToNot(HaveOccurred()) }) expectStreamToExitWith := func(stream <-chan warden.ProcessStream, status int) { for chunk := range stream { if chunk.ExitStatus != nil {
Expect(err).ToNot(HaveOccurred()) }) restartServer := func() { err := runner.Stop() Expect(err).ToNot(HaveOccurred()) err = runner.Start() Expect(err).ToNot(HaveOccurred()) } It("retains the container list", func() { restartServer() handles := getContainerHandles() Expect(handles).To(ContainElement(container.Handle())) }) Describe("a started job", func() { It("continues to stream", func() { processID, runStream, err := container.Run(warden.ProcessSpec{ Script: "while true; do echo hi; sleep 0.5; done", }) Expect(err).ToNot(HaveOccurred()) restartServer() Eventually(runStream).Should(BeClosed()) stream, err := container.Attach(processID)