1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/system/ping_test.go
Sam Whited b37c214e3c testutil: make testing packages public
This was done with something along the lines of:

```
mv internal/test testutil
pushd testutil/; grep -IRl "package test" | xargs -I '{}' sed -i -e 's|package test|package testutil|g' {}; popd
mv internal/testutil/*.go testutil/ && rm -rf internal/
grep -IRl "github.com\/docker\/docker\/internal\/test" | xargs -I '{}' sed -i -e 's|github.com/docker/docker/internal/test|github.com/docker/docker/test|g' {}
goimports .
```

I also modified the basic plugin path in testutil/fixtures/plugin.

Signed-off-by: Sam Whited <sam@samwhited.com>
2019-09-11 07:47:23 -05:00

59 lines
1.5 KiB
Go

package system // import "github.com/docker/docker/integration/system"
import (
"net/http"
"strings"
"testing"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/testutil/request"
"gotest.tools/assert"
"gotest.tools/skip"
)
func TestPingCacheHeaders(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature")
defer setupTest(t)()
res, _, err := request.Get("/_ping")
assert.NilError(t, err)
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Equal(t, hdr(res, "Cache-Control"), "no-cache, no-store, must-revalidate")
assert.Equal(t, hdr(res, "Pragma"), "no-cache")
}
func TestPingGet(t *testing.T) {
defer setupTest(t)()
res, body, err := request.Get("/_ping")
assert.NilError(t, err)
b, err := request.ReadBody(body)
assert.NilError(t, err)
assert.Equal(t, string(b), "OK")
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Check(t, hdr(res, "API-Version") != "")
}
func TestPingHead(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature")
defer setupTest(t)()
res, body, err := request.Head("/_ping")
assert.NilError(t, err)
b, err := request.ReadBody(body)
assert.NilError(t, err)
assert.Equal(t, 0, len(b))
assert.Equal(t, res.StatusCode, http.StatusOK)
assert.Check(t, hdr(res, "API-Version") != "")
}
func hdr(res *http.Response, name string) string {
val, ok := res.Header[http.CanonicalHeaderKey(name)]
if !ok || len(val) == 0 {
return ""
}
return strings.Join(val, ", ")
}