Merge pull request #459 from technosophos/fix/test-list-deployments

fix(manager): add test for listDeploymentsRequestHandler
pull/467/head
Matt Butcher 9 years ago
commit 6985048298

@ -76,3 +76,31 @@ func TestCreateDeployments(t *testing.T) {
t.Errorf("Expected status %d, got %d", http.StatusCreated, res.StatusCode)
}
}
func TestListDeployments(t *testing.T) {
c := stubContext()
s := httpHarness(c, "GET /deployments", listDeploymentsHandlerFunc)
defer s.Close()
man := c.Manager.(*mockManager)
man.deployments = []*common.Deployment{
{Name: "one", State: &common.DeploymentState{Status: common.CreatedStatus}},
{Name: "two", State: &common.DeploymentState{Status: common.DeployedStatus}},
}
res, err := http.Get(s.URL + "/deployments")
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 []string
if err := json.NewDecoder(res.Body).Decode(&out); err != nil {
t.Errorf("Failed to parse results: %s", err)
return
}
if len(out) != 2 {
t.Errorf("Expected 2 names, got %d", len(out))
}
}

@ -47,16 +47,28 @@ func httpHarness(c *router.Context, route string, fn router.HandlerFunc) *httpte
func stubContext() *router.Context {
return &router.Context{
Config: &router.Config{},
Manager: &mockManager{},
Manager: newMockManager(),
CredentialProvider: repo.NewInmemCredentialProvider(),
Encoder: httputil.DefaultEncoder,
}
}
type mockManager struct{}
func newMockManager() *mockManager {
return &mockManager{
deployments: []*common.Deployment{},
}
}
type mockManager struct {
deployments []*common.Deployment
}
func (m *mockManager) ListDeployments() ([]common.Deployment, error) {
return []common.Deployment{}, nil
d := make([]common.Deployment, len(m.deployments))
for i, dd := range m.deployments {
d[i] = *dd
}
return d, nil
}
func (m *mockManager) GetDeployment(name string) (*common.Deployment, error) {

Loading…
Cancel
Save