2019-04-09 08:07:30 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-03-30 13:15:42 +00:00
|
|
|
"github.com/docker/docker/api"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2021-03-30 13:15:42 +00:00
|
|
|
"gotest.tools/v3/env"
|
2019-04-09 08:07:30 +00:00
|
|
|
)
|
|
|
|
|
2021-03-30 13:15:42 +00:00
|
|
|
func TestOptionWithHostFromEnv(t *testing.T) {
|
|
|
|
c, err := NewClientWithOpts(WithHostFromEnv())
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, c.client != nil)
|
|
|
|
assert.Equal(t, c.host, DefaultDockerHost)
|
|
|
|
assert.Equal(t, c.proto, defaultProto)
|
|
|
|
assert.Equal(t, c.addr, defaultAddr)
|
|
|
|
assert.Equal(t, c.basePath, "")
|
|
|
|
|
|
|
|
defer env.Patch(t, "DOCKER_HOST", "tcp://foo.example.com:2376/test/")()
|
|
|
|
|
|
|
|
c, err = NewClientWithOpts(WithHostFromEnv())
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, c.client != nil)
|
|
|
|
assert.Equal(t, c.host, "tcp://foo.example.com:2376/test/")
|
|
|
|
assert.Equal(t, c.proto, "tcp")
|
|
|
|
assert.Equal(t, c.addr, "foo.example.com:2376")
|
|
|
|
assert.Equal(t, c.basePath, "/test/")
|
|
|
|
}
|
|
|
|
|
2019-04-09 08:07:30 +00:00
|
|
|
func TestOptionWithTimeout(t *testing.T) {
|
|
|
|
timeout := 10 * time.Second
|
|
|
|
c, err := NewClientWithOpts(WithTimeout(timeout))
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, c.client != nil)
|
|
|
|
assert.Equal(t, c.client.Timeout, timeout)
|
|
|
|
}
|
2021-03-30 13:15:42 +00:00
|
|
|
|
|
|
|
func TestOptionWithVersionFromEnv(t *testing.T) {
|
|
|
|
c, err := NewClientWithOpts(WithVersionFromEnv())
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, c.client != nil)
|
|
|
|
assert.Equal(t, c.version, api.DefaultVersion)
|
|
|
|
assert.Equal(t, c.manualOverride, false)
|
|
|
|
|
|
|
|
defer env.Patch(t, "DOCKER_API_VERSION", "2.9999")()
|
|
|
|
|
|
|
|
c, err = NewClientWithOpts(WithVersionFromEnv())
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, c.client != nil)
|
|
|
|
assert.Equal(t, c.version, "2.9999")
|
|
|
|
assert.Equal(t, c.manualOverride, true)
|
|
|
|
}
|