github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/system/ping_test.go (about) 1 package system // import "github.com/docker/docker/integration/system" 2 3 import ( 4 "net/http" 5 "strings" 6 "testing" 7 8 "github.com/docker/docker/api/types/versions" 9 "github.com/docker/docker/testutil/request" 10 "gotest.tools/v3/assert" 11 "gotest.tools/v3/skip" 12 ) 13 14 func TestPingCacheHeaders(t *testing.T) { 15 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature") 16 defer setupTest(t)() 17 18 res, _, err := request.Get("/_ping") 19 assert.NilError(t, err) 20 assert.Equal(t, res.StatusCode, http.StatusOK) 21 22 assert.Equal(t, hdr(res, "Cache-Control"), "no-cache, no-store, must-revalidate") 23 assert.Equal(t, hdr(res, "Pragma"), "no-cache") 24 } 25 26 func TestPingGet(t *testing.T) { 27 defer setupTest(t)() 28 29 res, body, err := request.Get("/_ping") 30 assert.NilError(t, err) 31 32 b, err := request.ReadBody(body) 33 assert.NilError(t, err) 34 assert.Equal(t, string(b), "OK") 35 assert.Equal(t, res.StatusCode, http.StatusOK) 36 assert.Check(t, hdr(res, "API-Version") != "") 37 } 38 39 func TestPingHead(t *testing.T) { 40 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature") 41 defer setupTest(t)() 42 43 res, body, err := request.Head("/_ping") 44 assert.NilError(t, err) 45 46 b, err := request.ReadBody(body) 47 assert.NilError(t, err) 48 assert.Equal(t, 0, len(b)) 49 assert.Equal(t, res.StatusCode, http.StatusOK) 50 assert.Check(t, hdr(res, "API-Version") != "") 51 } 52 53 func hdr(res *http.Response, name string) string { 54 val, ok := res.Header[http.CanonicalHeaderKey(name)] 55 if !ok || len(val) == 0 { 56 return "" 57 } 58 return strings.Join(val, ", ") 59 }