1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

integration: TestPingSwarmHeader(): fix incorrect ping, and cleanup

I noticed I made a mistake in the first ping ("before swarm init"), which
was not specifying the daemon's socket path and because of that testing
against the main integration daemon (not the locally spun up daemon).

While fixing that, I wondered why the test didn't actually use the client
for the requests (to also verify the client converted the response), so
I rewrote the test to use `client.Ping()` and to verify the ping response
has the expected values set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-05-29 15:17:37 +02:00
parent 69adaa894d
commit a3b1b66bb3
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -66,30 +66,30 @@ func TestPingSwarmHeader(t *testing.T) {
ctx := context.TODO()
t.Run("before swarm init", func(t *testing.T) {
res, _, err := request.Get("/_ping")
p, err := client.Ping(ctx)
assert.NilError(t, err)
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Equal(t, hdr(res, "Swarm"), "inactive")
assert.Equal(t, p.SwarmStatus.NodeState, swarm.LocalNodeStateInactive)
assert.Equal(t, p.SwarmStatus.ControlAvailable, false)
})
_, err := client.SwarmInit(ctx, swarm.InitRequest{ListenAddr: "127.0.0.1", AdvertiseAddr: "127.0.0.1:2377"})
assert.NilError(t, err)
t.Run("after swarm init", func(t *testing.T) {
res, _, err := request.Get("/_ping", request.Host(d.Sock()))
p, err := client.Ping(ctx)
assert.NilError(t, err)
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Equal(t, hdr(res, "Swarm"), "active/manager")
assert.Equal(t, p.SwarmStatus.NodeState, swarm.LocalNodeStateActive)
assert.Equal(t, p.SwarmStatus.ControlAvailable, true)
})
err = client.SwarmLeave(ctx, true)
assert.NilError(t, err)
t.Run("after swarm leave", func(t *testing.T) {
res, _, err := request.Get("/_ping", request.Host(d.Sock()))
p, err := client.Ping(ctx)
assert.NilError(t, err)
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Equal(t, hdr(res, "Swarm"), "inactive")
assert.Equal(t, p.SwarmStatus.NodeState, swarm.LocalNodeStateInactive)
assert.Equal(t, p.SwarmStatus.ControlAvailable, false)
})
}