Commit 3539586c authored by Matt Butcher's avatar Matt Butcher

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

fix(manager): add test for delete deployment API
parents 61a9296b efeac792
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment