Example #1
0
func TestCreateDeployment(t *testing.T) {
	setup()
	defer teardown()
	fakeManager := FakeManager{ResponseForCreate: agent.DeploymentResponseLite{ID: 123}}
	handlerCalled := false
	handler := func(w http.ResponseWriter, r *http.Request) {
		handlerCalled = true
		api.CreateDeployment(&fakeManager, w, r)
	}
	router.Methods("POST").Path(api.URLForDeployments()).Name("test").HandlerFunc(handler)

	b := agent.DeploymentBlueprint{}
	dr, err := client.CreateDeployment(b)
	assert.NoError(t, err)
	assert.Equal(t, 123, dr.ID)
	assert.True(t, handlerCalled)
}
Example #2
0
func TestListDeployments(t *testing.T) {
	setup()
	defer teardown()
	drs := []agent.DeploymentResponseLite{{Name: "Test"}}
	fakeManager := FakeManager{Deployments: drs}

	handlerCalled := false
	handler := func(w http.ResponseWriter, r *http.Request) {
		handlerCalled = true
		api.ListDeployments(&fakeManager, w, r)
	}
	router.Methods("GET").Path(api.URLForDeployments()).Name("test").HandlerFunc(handler)

	d, err := client.ListDeployments()
	assert.NoError(t, err)
	if assert.Len(t, d, 1) {
		assert.Equal(t, "Test", d[0].Name)
	}
	assert.True(t, handlerCalled)
}
Example #3
0
// CreateDeployment creates a new deployment from a blueprint.
func (c APIClient) CreateDeployment(b agent.DeploymentBlueprint) (agent.DeploymentResponseLite, error) {
	var resp agent.DeploymentResponseLite
	err := c.doRequest("POST", api.URLForDeployments(), &resp, b)
	return resp, err
}
Example #4
0
// ListDeployments fetches a list of deployments.
func (c APIClient) ListDeployments() ([]agent.DeploymentResponseLite, error) {
	var deployments []agent.DeploymentResponseLite
	err := c.doRequest("GET", api.URLForDeployments(), &deployments, nil)
	return deployments, err
}