Ejemplo n.º 1
0
func (dotNetBackend *dotNetBackend) Containers(props garden.Properties) ([]garden.Container, error) {
	containers := []garden.Container{}
	u, err := url.Parse("/api/containers")
	if len(props) > 0 {
		jsonString, err := json.Marshal(props)
		if err != nil {
			return containers, err
		}
		values := url.Values{"q": []string{string(jsonString)}}
		u.RawQuery = values.Encode()
	}

	var ids []string
	err = dotNetBackend.client.Get(u.String(), &ids)
	for _, containerId := range ids {
		containers = append(containers, container.NewContainer(dotNetBackend.client, containerId, dotNetBackend.logger))
	}
	return containers, err
}
Ejemplo n.º 2
0
	Describe("Containers", func() {
		Context("when no properties are specified", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/api/containers"),
						ghttp.RespondWith(200, `["MyFirstContainer","MySecondContainer"]`),
					),
				)
			})
			It("returns a list of containers", func() {
				containers, err := dotNetBackend.Containers(nil)
				Expect(err).NotTo(HaveOccurred())
				Expect(containers).Should(Equal([]garden.Container{
					container.NewContainer(client, "MyFirstContainer", logger),
					container.NewContainer(client, "MySecondContainer", logger),
				}))
			})
		})

		Context("when given properties to filter by", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/api/containers", "q=%7B%22a%22%3A%22c%22%7D"),
						ghttp.RespondWith(200, `["MatchingContainer"]`),
					),
				)
			})
			It("passes them to containerizer and returns only containers with matching properties", func() {
Ejemplo n.º 3
0
}

var _ = Describe("container", func() {
	var server *ghttp.Server
	var container garden.Container
	var logger *lagertest.TestLogger
	var client *dotnet.Client
	var externalIP string

	BeforeEach(func() {
		server = ghttp.NewServer()
		externalIP = "10.11.12.13"
		logger = lagertest.NewTestLogger("container")
		serverUri, _ := url.Parse(server.URL())
		client = dotnet.NewClient(logger, serverUri)
		container = netContainer.NewContainer(client, "containerhandle", logger)
	})

	AfterEach(func() {
		//shut down the server between tests
		if server.HTTPTestServer != nil {
			server.Close()
		}
	})

	Describe("Info", func() {
		Describe("for a valid handle", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/api/containers/containerhandle/info"),
Ejemplo n.º 4
0
func (dotNetBackend *dotNetBackend) Lookup(handle string) (garden.Container, error) {
	netContainer := container.NewContainer(dotNetBackend.client, handle, dotNetBackend.logger)
	return netContainer, nil
}
Ejemplo n.º 5
0
func (dotNetBackend *dotNetBackend) Create(containerSpec garden.ContainerSpec) (garden.Container, error) {
	var returnedContainer createContainerResponse
	err := dotNetBackend.client.Post("/api/containers", containerSpec, &returnedContainer)
	netContainer := container.NewContainer(dotNetBackend.client, returnedContainer.Handle, dotNetBackend.logger)
	return netContainer, err
}