|
|
@ -1,20 +1,18 @@
|
|
|
|
package flags
|
|
|
|
package flags
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestEnvConfig_Defaults(t *testing.T) {
|
|
|
|
func TestEnvConfig_Defaults(t *testing.T) {
|
|
|
|
// Unset testing environments own variables, since those are not what is under test
|
|
|
|
// Unset testing environments own variables, since those are not what is under test
|
|
|
|
os.Unsetenv("DOCKER_TLS_VERIFY")
|
|
|
|
_ = os.Unsetenv("DOCKER_TLS_VERIFY")
|
|
|
|
os.Unsetenv("DOCKER_HOST")
|
|
|
|
_ = os.Unsetenv("DOCKER_HOST")
|
|
|
|
|
|
|
|
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
SetDefaults()
|
|
|
|
SetDefaults()
|
|
|
@ -48,10 +46,7 @@ func TestEnvConfig_Custom(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestGetSecretsFromFilesWithString(t *testing.T) {
|
|
|
|
func TestGetSecretsFromFilesWithString(t *testing.T) {
|
|
|
|
value := "supersecretstring"
|
|
|
|
value := "supersecretstring"
|
|
|
|
|
|
|
|
t.Setenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD", value)
|
|
|
|
err := os.Setenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD", value)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer os.Unsetenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testGetSecretsFromFiles(t, "notification-email-server-password", value)
|
|
|
|
testGetSecretsFromFiles(t, "notification-email-server-password", value)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -60,18 +55,15 @@ func TestGetSecretsFromFilesWithFile(t *testing.T) {
|
|
|
|
value := "megasecretstring"
|
|
|
|
value := "megasecretstring"
|
|
|
|
|
|
|
|
|
|
|
|
// Create the temporary file which will contain a secret.
|
|
|
|
// Create the temporary file which will contain a secret.
|
|
|
|
file, err := ioutil.TempFile(os.TempDir(), "watchtower-")
|
|
|
|
file, err := os.CreateTemp(t.TempDir(), "watchtower-")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer os.Remove(file.Name()) // Make sure to remove the temporary file later.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write the secret to the temporary file.
|
|
|
|
// Write the secret to the temporary file.
|
|
|
|
secret := []byte(value)
|
|
|
|
_, err = file.Write([]byte(value))
|
|
|
|
_, err = file.Write(secret)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NoError(t, file.Close())
|
|
|
|
|
|
|
|
|
|
|
|
err = os.Setenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD", file.Name())
|
|
|
|
t.Setenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD", file.Name())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer os.Unsetenv("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testGetSecretsFromFiles(t, "notification-email-server-password", value)
|
|
|
|
testGetSecretsFromFiles(t, "notification-email-server-password", value)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,16 +72,15 @@ func TestGetSliceSecretsFromFiles(t *testing.T) {
|
|
|
|
values := []string{"entry2", "", "entry3"}
|
|
|
|
values := []string{"entry2", "", "entry3"}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the temporary file which will contain a secret.
|
|
|
|
// Create the temporary file which will contain a secret.
|
|
|
|
file, err := ioutil.TempFile(os.TempDir(), "watchtower-")
|
|
|
|
file, err := os.CreateTemp(t.TempDir(), "watchtower-")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer os.Remove(file.Name()) // Make sure to remove the temporary file later.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write the secret to the temporary file.
|
|
|
|
// Write the secret to the temporary file.
|
|
|
|
for _, value := range values {
|
|
|
|
for _, value := range values {
|
|
|
|
_, err = file.WriteString("\n" + value)
|
|
|
|
_, err = file.WriteString("\n" + value)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
file.Close()
|
|
|
|
require.NoError(t, file.Close())
|
|
|
|
|
|
|
|
|
|
|
|
testGetSecretsFromFiles(t, "notification-url", `[entry1,entry2,entry3]`,
|
|
|
|
testGetSecretsFromFiles(t, "notification-url", `[entry1,entry2,entry3]`,
|
|
|
|
`--notification-url`, "entry1",
|
|
|
|
`--notification-url`, "entry1",
|
|
|
@ -166,9 +157,7 @@ func TestProcessFlagAliases(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestProcessFlagAliasesLogLevelFromEnvironment(t *testing.T) {
|
|
|
|
func TestProcessFlagAliasesLogLevelFromEnvironment(t *testing.T) {
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
err := os.Setenv("WATCHTOWER_DEBUG", `true`)
|
|
|
|
t.Setenv("WATCHTOWER_DEBUG", `true`)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer os.Unsetenv("WATCHTOWER_DEBUG")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetDefaults()
|
|
|
|
SetDefaults()
|
|
|
|
RegisterDockerFlags(cmd)
|
|
|
|
RegisterDockerFlags(cmd)
|
|
|
@ -202,9 +191,7 @@ func TestProcessFlagAliasesSchedAndInterval(t *testing.T) {
|
|
|
|
func TestProcessFlagAliasesScheduleFromEnvironment(t *testing.T) {
|
|
|
|
func TestProcessFlagAliasesScheduleFromEnvironment(t *testing.T) {
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
cmd := new(cobra.Command)
|
|
|
|
|
|
|
|
|
|
|
|
err := os.Setenv("WATCHTOWER_SCHEDULE", `@hourly`)
|
|
|
|
t.Setenv("WATCHTOWER_SCHEDULE", `@hourly`)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer os.Unsetenv("WATCHTOWER_SCHEDULE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetDefaults()
|
|
|
|
SetDefaults()
|
|
|
|
RegisterDockerFlags(cmd)
|
|
|
|
RegisterDockerFlags(cmd)
|
|
|
|