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

var _ = Describe("simple list of vms", func() {
	It("GET /deployments/$name/vms to return []DeploymentVM{}", func() {
		request := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/deployments/cf-warden/vms",
			Response: gogobosh.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))
Пример #3
0
		request := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/releases",
			Response: gogobosh.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"
				        ]
				      }
				    ]
				  }
				]`}})
Пример #4
0
	It("GET /info to return Director{}", func() {
		request := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/info",
			Response: gogobosh.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)
Пример #5
0
)

var _ = Describe("get list of stemcells", func() {
	It("GET /stemcells to return []DirectorStemcell{}", func() {
		request := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/stemcells",
			Response: gogobosh.TestResponse{
				Status: http.StatusOK,
				Body: `[
				  {
				    "name": "bosh-stemcell",
				    "version": "993",
				    "cid": "stemcell-6e6b9689-8b03-42cd-a6de-7784e3c421ec",
				    "deployments": [
				      "#<Bosh::Director::Models::Deployment:0x0000000474bdb0>"
				    ]
				  },
				  {
				    "name": "bosh-warden-boshlite-ubuntu",
				    "version": "24",
				    "cid": "stemcell-6936d497-b8cd-4e12-af0a-5f2151834a1a",
				    "deployments": [

				    ]
				  }
				]`}})
		ts, handler, repo := createDirectorRepo(request)
		defer ts.Close()

		stemcells, apiResponse := repo.GetStemcells()
package gogobosh_test

import (
	gogobosh "github.com/cloudfoundry-community/gogobosh"
	. "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 := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/deployments/cf-warden/vms?format=full",
			Response: gogobosh.TestResponse{
				Status: http.StatusFound,
				Header: http.Header{
					"Location": {"https://some.host/tasks/12"},
				},
			},
		})
		taskOutputRequest := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/tasks/12/output?type=result",
			Response: gogobosh.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,
import (
	gogobosh "github.com/cloudfoundry-community/gogobosh"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"net/http"
)

var _ = Describe("TaskStatus", func() {
	It("GetTaskStatus returns TaskStatus{}", func() {
		request := gogobosh.NewDirectorTestRequest(gogobosh.TestRequest{
			Method: "GET",
			Path:   "/tasks/1",
			Response: gogobosh.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))
	"net/http"
)

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

		deployments, apiResponse := repo.GetDeployments()