Merge pull request #26503 from clnperez/swarm-test-move-err-check

swarm: always check err before http status in tests
This commit is contained in:
Tõnis Tiigi 2016-09-13 10:53:55 -07:00 committed by GitHub
commit 711455d34e
1 changed files with 17 additions and 17 deletions

View File

@ -106,7 +106,7 @@ func (d *SwarmDaemon) createService(c *check.C, f ...serviceConstructor) string
}
status, out, err := d.SockRequest("POST", "/services/create", service.Spec)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf("output: %q", string(out)))
var scr types.ServiceCreateResponse
@ -117,8 +117,8 @@ func (d *SwarmDaemon) createService(c *check.C, f ...serviceConstructor) string
func (d *SwarmDaemon) getService(c *check.C, id string) *swarm.Service {
var service swarm.Service
status, out, err := d.SockRequest("GET", "/services/"+id, nil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil)
c.Assert(json.Unmarshal(out, &service), checker.IsNil)
return &service
}
@ -133,8 +133,8 @@ func (d *SwarmDaemon) getServiceTasks(c *check.C, service string) []swarm.Task {
c.Assert(err, checker.IsNil)
status, out, err := d.SockRequest("GET", "/tasks?filters="+filters, nil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &tasks), checker.IsNil)
return tasks
}
@ -168,8 +168,8 @@ func (d *SwarmDaemon) checkRunningTaskImages(c *check.C) (interface{}, check.Com
c.Assert(err, checker.IsNil)
status, out, err := d.SockRequest("GET", "/tasks?filters="+filters, nil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &tasks), checker.IsNil)
result := make(map[string]int)
@ -196,8 +196,8 @@ func (d *SwarmDaemon) getTask(c *check.C, id string) swarm.Task {
var task swarm.Task
status, out, err := d.SockRequest("GET", "/tasks/"+id, nil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &task), checker.IsNil)
return task
}
@ -208,21 +208,21 @@ func (d *SwarmDaemon) updateService(c *check.C, service *swarm.Service, f ...ser
}
url := fmt.Sprintf("/services/%s/update?version=%d", service.ID, service.Version.Index)
status, out, err := d.SockRequest("POST", url, service.Spec)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
}
func (d *SwarmDaemon) removeService(c *check.C, id string) {
status, out, err := d.SockRequest("DELETE", "/services/"+id, nil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil)
}
func (d *SwarmDaemon) getNode(c *check.C, id string) *swarm.Node {
var node swarm.Node
status, out, err := d.SockRequest("GET", "/nodes/"+id, nil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil)
c.Assert(json.Unmarshal(out, &node), checker.IsNil)
c.Assert(node.ID, checker.Equals, id)
return &node
@ -235,8 +235,8 @@ func (d *SwarmDaemon) removeNode(c *check.C, id string, force bool) {
}
status, out, err := d.SockRequest("DELETE", url, nil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil)
}
func (d *SwarmDaemon) updateNode(c *check.C, id string, f ...nodeConstructor) {
@ -251,7 +251,7 @@ func (d *SwarmDaemon) updateNode(c *check.C, id string, f ...nodeConstructor) {
time.Sleep(100 * time.Millisecond)
continue
}
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
return
}
@ -259,7 +259,7 @@ func (d *SwarmDaemon) updateNode(c *check.C, id string, f ...nodeConstructor) {
func (d *SwarmDaemon) listNodes(c *check.C) []swarm.Node {
status, out, err := d.SockRequest("GET", "/nodes", nil)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
nodes := []swarm.Node{}
@ -269,7 +269,7 @@ func (d *SwarmDaemon) listNodes(c *check.C) []swarm.Node {
func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
status, out, err := d.SockRequest("GET", "/services", nil)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
services := []swarm.Service{}
@ -280,7 +280,7 @@ func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service {
func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm {
var sw swarm.Swarm
status, out, err := d.SockRequest("GET", "/swarm", nil)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
return sw
@ -293,27 +293,27 @@ func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) {
}
url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index)
status, out, err := d.SockRequest("POST", url, sw.Spec)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
}
func (d *SwarmDaemon) rotateTokens(c *check.C) {
var sw swarm.Swarm
status, out, err := d.SockRequest("GET", "/swarm", nil)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
url := fmt.Sprintf("/swarm/update?version=%d&rotateWorkerToken=true&rotateManagerToken=true", sw.Version.Index)
status, out, err = d.SockRequest("POST", url, sw.Spec)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
}
func (d *SwarmDaemon) joinTokens(c *check.C) swarm.JoinTokens {
var sw swarm.Swarm
status, out, err := d.SockRequest("GET", "/swarm", nil)
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(json.Unmarshal(out, &sw), checker.IsNil)
return sw.JoinTokens