"github.com/pivotal-cf-experimental/garden/command_runner/fake_command_runner"
	. "github.com/pivotal-cf-experimental/garden/command_runner/fake_command_runner/matchers"
	"github.com/pivotal-cf-experimental/garden/linux_backend"
	"github.com/pivotal-cf-experimental/garden/linux_backend/bandwidth_manager/fake_bandwidth_manager"
	"github.com/pivotal-cf-experimental/garden/linux_backend/cgroups_manager/fake_cgroups_manager"
	"github.com/pivotal-cf-experimental/garden/linux_backend/network_pool"
	"github.com/pivotal-cf-experimental/garden/linux_backend/port_pool/fake_port_pool"
	"github.com/pivotal-cf-experimental/garden/linux_backend/quota_manager/fake_quota_manager"
)

var fakeCgroups *fake_cgroups_manager.FakeCgroupsManager
var fakeQuotaManager *fake_quota_manager.FakeQuotaManager
var fakeBandwidthManager *fake_bandwidth_manager.FakeBandwidthManager
var fakeRunner *fake_command_runner.FakeCommandRunner
var containerResources *linux_backend.Resources
var container *linux_backend.LinuxContainer
var fakePortPool *fake_port_pool.FakePortPool

var _ = Describe("Linux containers", func() {
	BeforeEach(func() {
		fakeRunner = fake_command_runner.New()

		fakeCgroups = fake_cgroups_manager.New("/cgroups", "some-id")

		fakeQuotaManager = fake_quota_manager.New()
		fakeBandwidthManager = fake_bandwidth_manager.New()

		_, ipNet, err := net.ParseCIDR("10.254.0.0/24")
		Expect(err).ToNot(HaveOccurred())

		fakePortPool = fake_port_pool.New(1000)
						cmd.Stdout.Write([]byte("container-2\n"))
						cmd.Stdout.Write([]byte("tmp\n"))
						cmd.Stdout.Write([]byte("container-3\n"))

						return nil
					},
				)

				err := pool.Prune(map[string]bool{})
				Expect(err).To(Equal(disaster))
			})
		})
	})

	Describe("destroying", func() {
		var createdContainer *linux_backend.LinuxContainer

		BeforeEach(func() {
			container, err := pool.Create(backend.ContainerSpec{})
			Expect(err).ToNot(HaveOccurred())

			createdContainer = container.(*linux_backend.LinuxContainer)

			createdContainer.Resources().AddPort(123)
			createdContainer.Resources().AddPort(456)
		})

		It("executes destroy.sh with the correct args and environment", func() {
			err := pool.Destroy(createdContainer)
			Expect(err).ToNot(HaveOccurred())