Commit edb6187e authored by Matt Butcher's avatar Matt Butcher

Merge pull request #464 from technosophos/fix/test-get-deployments

fix(manager): add test for getDeployments*
parents 27678bcb 30142ba6
......@@ -104,3 +104,35 @@ func TestListDeployments(t *testing.T) {
t.Errorf("Expected 2 names, got %d", len(out))
}
}
func TestGetDeployments(t *testing.T) {
c := stubContext()
s := httpHarness(c, "GET /deployments/*", getDeploymentHandlerFunc)
defer s.Close()
man := c.Manager.(*mockManager)
man.deployments = []*common.Deployment{
{Name: "portunes", State: &common.DeploymentState{Status: common.CreatedStatus}},
}
res, err := http.Get(s.URL + "/deployments/portunes")
if err != nil {
t.Errorf("Failed GET: %s", err)
} else if res.StatusCode != http.StatusOK {
t.Errorf("Unexpected status code: %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)
}
if out.State.Status != common.CreatedStatus {
t.Errorf("Unexpected status %d", out.State.Status)
}
}
......@@ -17,6 +17,7 @@ limitations under the License.
package main
import (
"errors"
"net/http/httptest"
"regexp"
......@@ -72,7 +73,14 @@ func (m *mockManager) ListDeployments() ([]common.Deployment, error) {
}
func (m *mockManager) GetDeployment(name string) (*common.Deployment, error) {
return &common.Deployment{}, nil
for _, d := range m.deployments {
if d.Name == name {
return d, nil
}
}
return nil, errors.New("mock error: No such deployment")
}
func (m *mockManager) CreateDeployment(t *common.Template) (*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