mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
Add docker api version parameter (#372)
* Add docker api version parameter * Note for minimum supported version * Tests for EnvConfig
This commit is contained in:
parent
7f7db72686
commit
f820eb5b3a
4 changed files with 63 additions and 8 deletions
39
internal/flags/flags_test.go
Normal file
39
internal/flags/flags_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package flags
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEnvConfig_Defaults(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
SetDefaults()
|
||||
RegisterDockerFlags(cmd)
|
||||
|
||||
err := EnvConfig(cmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "unix:///var/run/docker.sock", os.Getenv("DOCKER_HOST"))
|
||||
assert.Equal(t, "", os.Getenv("DOCKER_TLS_VERIFY"))
|
||||
assert.Equal(t, DockerAPIMinVersion, os.Getenv("DOCKER_API_VERSION"))
|
||||
}
|
||||
|
||||
func TestEnvConfig_Custom(t *testing.T) {
|
||||
cmd := new(cobra.Command)
|
||||
SetDefaults()
|
||||
RegisterDockerFlags(cmd)
|
||||
|
||||
err := cmd.ParseFlags([]string{"--host", "some-custom-docker-host", "--tlsverify", "--api-version", "1.99"})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = EnvConfig(cmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "some-custom-docker-host", os.Getenv("DOCKER_HOST"))
|
||||
assert.Equal(t, "1", os.Getenv("DOCKER_TLS_VERIFY"))
|
||||
assert.Equal(t, "1.99", os.Getenv("DOCKER_API_VERSION"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue