// Shared helper for asserting that a /tasks/ID is requested and returns a models.TaskStatus response
func taskTestRequest(taskID int, state string) testhelpers.TestRequest {
	baseJSON := `{
	  "id": %d,
	  "state": "%s",
	  "description": "some task",
	  "timestamp": 1390174354,
	  "result": null,
	  "user": "******"
	}`
	return testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
		Method: "GET",
		Path:   fmt.Sprintf("/tasks/%d", taskID),
		Response: testhelpers.TestResponse{
			Status: http.StatusOK,
			Body:   fmt.Sprintf(baseJSON, taskID, state),
		},
	})
}
package api_test

import (
	"github.com/cloudfoundry-community/gogobosh/testhelpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"net/http"
)

var _ = Describe("parse full vms task output", func() {
	It("GET /deployments/cf-warden/vms?format=full to return Director{}", func() {
		vmsRequest := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/deployments/cf-warden/vms?format=full",
			Response: testhelpers.TestResponse{
				Status: http.StatusFound,
				Header: http.Header{
					"Location": {"https://some.host/tasks/12"},
				},
			},
		})
		taskOutputRequest := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/tasks/12/output?type=result",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `{"vm_cid":"vm-a1a3d634-367d-4b75-940c-ef7742a970d9","ips":["10.244.1.14"],"dns":[],"agent_id":"c0da6161-e66f-4910-a0eb-dc6fc19b4b25","job_name":"hm9000_z1","index":0,"job_state":"running","resource_pool":"medium_z1","vitals":{"load":["0.11","0.21","0.18"],"cpu":{"user":"******","sys":"2.8","wait":"0.1"},"mem":{"percent":"46.8","kb":"2864212"},"swap":{"percent":"0.0","kb":"0"},"disk":{"system":{"percent":null},"persistent":{"percent":"1"}}},"resurrection_paused":false}
				{"vm_cid":"vm-affdbbdb-b91e-4838-b068-f1a057242169","ips":["10.244.0.38"],"dns":[],"agent_id":"bec309f8-0e2d-4843-9db3-a419adab4d38","job_name":"etcd_leader_z1","index":0,"job_state":"running","resource_pool":"medium_z1","vitals":{"load":["0.13","0.22","0.18"],"cpu":{"user":"******","sys":"2.0","wait":"0.1"},"mem":{"percent":"46.8","kb":"2863012"},"swap":{"percent":"0.0","kb":"0"},"disk":{"system":{"percent":null},"persistent":{"percent":"1"}}},"resurrection_paused":false}
				`}})

		ts, handler, repo := createDirectorRepo(
			vmsRequest,
	. "github.com/onsi/gomega"
	"net/http"
)

var _ = Describe("simple list of vms", func() {
	It("GET /deployments/$name/vms to return []models.DeploymentVM{}", func() {
		request := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/deployments/cf-warden/vms",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `[
				  {
				    "agent_id": "b11f259c-79dd-4d6d-8aa5-5969d569a2a6",
				    "cid": "vm-8a03a314-6f16-45f6-a377-1a36e763ee45",
				    "job": "ha_proxy_z1",
				    "index": 0
				  },
				  {
				    "agent_id": "5c7708c9-1631-48b3-9833-6b7d0f6c6cd4",
				    "cid": "vm-37926289-487d-4ee9-b556-9684350d1d14",
				    "job": "login_z1",
				    "index": 0
				  }
				]`}})
		ts, handler, repo := createDirectorRepo(request)
		defer ts.Close()

		deploymentVMs, apiResponse := repo.ListDeploymentVMs("cf-warden")

		Expect(len(deploymentVMs)).To(Equal(2))
	. "github.com/onsi/gomega"
)

var _ = Describe("Deployments", func() {
	It("GetDeployments() - list of deployments", func() {
		request := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/deployments",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `[
				  {
				    "name": "cf-warden",
				    "releases": [
				      {
				        "name": "cf",
				        "version": "153"
				      }
				    ],
				    "stemcells": [
				      {
				        "name": "bosh-stemcell",
				        "version": "993"
				      }
				    ]
				  }
				]`}})
		ts, handler, repo := createDirectorRepo(request)
		defer ts.Close()

		deployments, apiResponse := repo.GetDeployments()
Esempio n. 5
0
	It("GET /info to return Director{}", func() {
		request := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/info",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `{
				  "name": "Bosh Lite Director",
				  "uuid": "bd462a15-213d-448c-aa5b-66624dad3f0e",
				  "version": "1.5.0.pre.1657 (14bc162c)",
				  "user": "******",
				  "cpi": "warden",
				  "features": {
				    "dns": {
				      "status": false,
				      "extras": {
				        "domain_name": "bosh"
				      }
				    },
				    "compiled_package_cache": {
				      "status": true,
				      "extras": {
				        "provider": "local"
				      }
				    },
				    "snapshots": {
				      "status": false
				    }
				  }
				}`}})
		ts, handler, repo := createDirectorRepo(request)
import (
	"github.com/cloudfoundry-community/gogobosh/testhelpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"net/http"
)

var _ = Describe("models.TaskStatus", func() {
	It("GetTaskStatus returns models.TaskStatus{}", func() {
		request := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/tasks/1",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `{
				  "id": 1,
				  "state": "done",
				  "description": "create release",
				  "timestamp": 1390068518,
				  "result": "Created release cf/153",
				  "user": "******"
				}`}})
		ts, handler, repo := createDirectorRepo(request)
		defer ts.Close()

		task, apiResponse := repo.GetTaskStatus(1)

		Expect(task.ID).To(Equal(1))
		Expect(task.State).To(Equal("done"))
		Expect(task.Description).To(Equal("create release"))
		Expect(task.TimeStamp).To(Equal(1390068518))
		request := testhelpers.NewDirectorTestRequest(testhelpers.TestRequest{
			Method: "GET",
			Path:   "/releases",
			Response: testhelpers.TestResponse{
				Status: http.StatusOK,
				Body: `[
				  {
				    "name": "cf",
				    "release_versions": [
				      {
				        "version": "153",
				        "commit_hash": "009fdd9a",
				        "uncommitted_changes": true,
				        "currently_deployed": true,
				        "job_names": [
				          "cloud_controller_ng",
				          "nats",
				          "dea_next",
				          "login",
				          "health_manager_next",
				          "uaa",
				          "debian_nfs_server",
				          "loggregator",
				          "postgres",
				          "dea_logging_agent",
				          "syslog_aggregator",
				          "narc",
				          "haproxy",
				          "hm9000",
				          "saml_login",
				          "nats_stream_forwarder",
				          "collector",
				          "pivotal_login",
				          "loggregator_trafficcontroller",
				          "etcd",
				          "gorouter"
				        ]
				      }
				    ]
				  }
				]`}})