summaryrefslogtreecommitdiff
path: root/integration
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2021-02-23 18:21:37 +0100
committerSebastiaan van Stijn <github@gone.nl>2022-03-25 23:54:14 +0100
commitadf4bf772d6316d6e166542b44b52536472745b5 (patch)
treef4b53f10206a73572292f043912daffaeefcd73a /integration
parent0729fbd343eb45a16e47d93cf1bd431c16743dda (diff)
downloaddocker-adf4bf772d6316d6e166542b44b52536472745b5.tar.gz
API: add "Swarm" header to _ping endpoint
This adds an additional "Swarm" header to the _ping endpoint response, which allows a client to detect if Swarm is enabled on the daemon, without having to call additional endpoints. This change is not versioned in the API, and will be returned irregardless of the API version that is used. Clients should fall back to using other endpoints to get this information if the header is not present. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'integration')
-rw-r--r--integration/system/ping_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/integration/system/ping_test.go b/integration/system/ping_test.go
index cd7a1c8eff..788d2df59e 100644
--- a/integration/system/ping_test.go
+++ b/integration/system/ping_test.go
@@ -1,11 +1,14 @@
package system // import "github.com/docker/docker/integration/system"
import (
+ "context"
"net/http"
"strings"
"testing"
+ "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
+ "github.com/docker/docker/testutil/daemon"
"github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert"
"gotest.tools/v3/skip"
@@ -50,6 +53,46 @@ func TestPingHead(t *testing.T) {
assert.Check(t, hdr(res, "API-Version") != "")
}
+func TestPingSwarmHeader(t *testing.T) {
+ skip.If(t, testEnv.IsRemoteDaemon)
+ skip.If(t, testEnv.DaemonInfo.OSType == "windows")
+
+ defer setupTest(t)()
+ d := daemon.New(t)
+ d.Start(t)
+ defer d.Stop(t)
+ client := d.NewClientT(t)
+ defer client.Close()
+ ctx := context.TODO()
+
+ t.Run("before swarm init", func(t *testing.T) {
+ res, _, err := request.Get("/_ping")
+ assert.NilError(t, err)
+ assert.Equal(t, res.StatusCode, http.StatusOK)
+ assert.Equal(t, hdr(res, "Swarm"), "inactive")
+ })
+
+ _, 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()))
+ assert.NilError(t, err)
+ assert.Equal(t, res.StatusCode, http.StatusOK)
+ assert.Equal(t, hdr(res, "Swarm"), "active/manager")
+ })
+
+ 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()))
+ assert.NilError(t, err)
+ assert.Equal(t, res.StatusCode, http.StatusOK)
+ assert.Equal(t, hdr(res, "Swarm"), "inactive")
+ })
+}
+
func hdr(res *http.Response, name string) string {
val, ok := res.Header[http.CanonicalHeaderKey(name)]
if !ok || len(val) == 0 {