Commit e1efff4b authored by Matt Butcher's avatar Matt Butcher

fix(manager): add test for listDeploymentsRequestHandler

parent d3975520
......@@ -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{
&common.Deployment{Name: "one", State: &common.DeploymentState{Status: common.CreatedStatus}},
&common.Deployment{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) {
......
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