Merge pull request #490 from technosophos/fix/manager-test-delete-deployment

fix(manager): add test for delete deployment API
pull/497/head
Matt Butcher 9 years ago
commit 3539586c1d

@ -136,3 +136,38 @@ func TestGetDeployments(t *testing.T) {
t.Errorf("Unexpected status %d", out.State.Status)
}
}
func TestDeleteDeployments(t *testing.T) {
c := stubContext()
s := httpHarness(c, "DELETE /deployments/*", deleteDeploymentHandlerFunc)
defer s.Close()
man := c.Manager.(*mockManager)
man.deployments = []*common.Deployment{
{Name: "portunes", State: &common.DeploymentState{Status: common.CreatedStatus}},
}
req, err := http.NewRequest("DELETE", s.URL+"/deployments/portunes", nil)
if err != nil {
t.Fatal("Failed to create delete request")
}
res, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("Failed to execute delete request: %s", err)
}
if res.StatusCode != 200 {
t.Errorf("Expected status code 200, got %d", res.StatusCode)
}
var out common.Deployment
if err := json.NewDecoder(res.Body).Decode(&out); err != nil {
t.Errorf("Failed to parse results: %s", err)
return
}
if out.Name != "portunes" {
t.Errorf("Unexpected name %q", out.Name)
}
}

@ -18,6 +18,7 @@ package main
import (
"errors"
"fmt"
"net/http/httptest"
"regexp"
@ -88,7 +89,13 @@ func (m *mockManager) CreateDeployment(depReq *common.DeploymentRequest) (*commo
}
func (m *mockManager) DeleteDeployment(name string, forget bool) (*common.Deployment, error) {
return &common.Deployment{}, nil
for _, d := range m.deployments {
if d.Name == name {
return d, nil
}
}
fmt.Printf("Could not find %s", name)
return nil, errors.New("Deployment not found")
}
func (m *mockManager) PutDeployment(name string, depReq *common.DeploymentRequest) (*common.Deployment, error) {

Loading…
Cancel
Save