Exemple #1
0
func (s *S) TestListUnitsByAppHandler(c *check.C) {
	a := app.App{Name: "myapp", Platform: "zend", TeamOwner: s.team.Name}
	err := app.CreateApp(&a, s.user)
	c.Assert(err, check.IsNil)
	err = a.AddUnits(2, "", nil)
	c.Assert(err, check.IsNil)
	req, err := http.NewRequest("GET", "/node/apps/myapp/containers", nil)
	c.Assert(err, check.IsNil)
	req.Header.Set("Authorization", "bearer "+s.token.GetValue())
	rec := httptest.NewRecorder()
	server := RunServer(true)
	server.ServeHTTP(rec, req)
	c.Assert(rec.Code, check.Equals, http.StatusOK)
	body, err := ioutil.ReadAll(rec.Body)
	c.Assert(err, check.IsNil)
	var result []provision.Unit
	var resultMap []map[string]interface{}
	err = json.Unmarshal(body, &result)
	c.Assert(err, check.IsNil)
	err = json.Unmarshal(body, &resultMap)
	c.Assert(err, check.IsNil)
	c.Assert(result[0].ID, check.Equals, "myapp-0")
	c.Assert(result[0].Type, check.Equals, "zend")
	c.Assert(result[1].ID, check.Equals, "myapp-1")
	c.Assert(result[1].Type, check.Equals, "zend")
	c.Assert(resultMap[0]["HostAddr"], check.Equals, "10.10.10.1")
	c.Assert(resultMap[1]["HostAddr"], check.Equals, "10.10.10.2")
	c.Assert(resultMap[0]["HostPort"], check.Equals, "1")
	c.Assert(resultMap[1]["HostPort"], check.Equals, "2")
	c.Assert(resultMap[0]["IP"], check.Equals, "10.10.10.1")
	c.Assert(resultMap[1]["IP"], check.Equals, "10.10.10.2")
}