mirror of
https://github.com/containrrr/watchtower.git
synced 2024-12-12 09:04:17 +02:00
refactor: move actions into internal
This commit is contained in:
parent
62f603bb25
commit
a425bf1024
@ -7,10 +7,10 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containrrr/watchtower/internal/actions"
|
||||
"github.com/containrrr/watchtower/internal/flags"
|
||||
"github.com/containrrr/watchtower/notifications"
|
||||
"github.com/containrrr/watchtower/pkg/actions"
|
||||
"github.com/containrrr/watchtower/pkg/container"
|
||||
"github.com/containrrr/watchtower/pkg/notifications"
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
"github.com/robfig/cron"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -2,6 +2,7 @@ package actions_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/containrrr/watchtower/internal/actions"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -43,7 +44,7 @@ var _ = Describe("the actions package", func() {
|
||||
When("given an empty array", func() {
|
||||
It("should not do anything", func() {
|
||||
client.TestData.Containers = []container.Container{}
|
||||
err := CheckForMultipleWatchtowerInstances(client, false)
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@ -56,7 +57,7 @@ var _ = Describe("the actions package", func() {
|
||||
"watchtower",
|
||||
time.Now()),
|
||||
}
|
||||
err := CheckForMultipleWatchtowerInstances(client, false)
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@ -84,7 +85,7 @@ var _ = Describe("the actions package", func() {
|
||||
}
|
||||
})
|
||||
It("should stop all but the latest one", func() {
|
||||
err := CheckForMultipleWatchtowerInstances(client, false)
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@ -111,12 +112,12 @@ var _ = Describe("the actions package", func() {
|
||||
}
|
||||
})
|
||||
It("should try to delete the image if the cleanup flag is true", func() {
|
||||
err := CheckForMultipleWatchtowerInstances(client, true)
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImage).To(BeTrue())
|
||||
})
|
||||
It("should not try to delete the image if the cleanup flag is false", func() {
|
||||
err := CheckForMultipleWatchtowerInstances(client, false)
|
||||
err := actions.CheckForMultipleWatchtowerInstances(client, false)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImage).To(BeFalse())
|
||||
})
|
@ -1,5 +1,6 @@
|
||||
package util
|
||||
|
||||
// SliceEqual compares two slices and checks whether they have equal content
|
||||
func SliceEqual(s1, s2 []string) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
@ -14,6 +15,7 @@ func SliceEqual(s1, s2 []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// SliceSubtract subtracts the content of slice a2 from slice a1
|
||||
func SliceSubtract(a1, a2 []string) []string {
|
||||
a := []string{}
|
||||
|
||||
@ -35,6 +37,7 @@ func SliceSubtract(a1, a2 []string) []string {
|
||||
return a
|
||||
}
|
||||
|
||||
// StringMapSubtract subtracts the content of structmap m2 from structmap m1
|
||||
func StringMapSubtract(m1, m2 map[string]string) map[string]string {
|
||||
m := map[string]string{}
|
||||
|
||||
@ -51,6 +54,7 @@ func StringMapSubtract(m1, m2 map[string]string) map[string]string {
|
||||
return m
|
||||
}
|
||||
|
||||
// StructMapSubtract subtracts the content of structmap m2 from structmap m1
|
||||
func StructMapSubtract(m1, m2 map[string]struct{}) map[string]struct{} {
|
||||
m := map[string]struct{}{}
|
||||
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestSliceEqual_True(t *testing.T) {
|
||||
s1 := []string{"a", "b", "c"}
|
||||
s2 := []string{"a", "b", "c"}
|
||||
|
@ -23,8 +23,7 @@ var _ = Describe("the container", func() {
|
||||
server := mocks.NewMockAPIServer()
|
||||
docker, _ = cli.NewClientWithOpts(
|
||||
cli.WithHost(server.URL),
|
||||
cli.WithHTTPClient(server.Client(),
|
||||
))
|
||||
cli.WithHTTPClient(server.Client()))
|
||||
client = dockerClient{
|
||||
api: docker,
|
||||
pullImages: false,
|
||||
|
@ -3,8 +3,8 @@ package container
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/containrrr/watchtower/pkg/container/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWatchtowerContainersFilter(t *testing.T) {
|
||||
|
@ -1,15 +1,11 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func TestEncodedEnvAuth_ShouldReturnAnErrorIfRepoEnvsAreUnset(t *testing.T) {
|
||||
os.Unsetenv("REPO_USER")
|
||||
os.Unsetenv("REPO_PASS")
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"strconv"
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -35,8 +35,8 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
|
||||
flags := c.PersistentFlags()
|
||||
|
||||
from, _ := flags.GetString("notification-email-from")
|
||||
to, _ := flags.GetString("notification-email-to")
|
||||
server, _ := flags.GetString("notification-email-server")
|
||||
to, _ := flags.GetString("notification-email-to")
|
||||
server, _ := flags.GetString("notification-email-server")
|
||||
user, _ := flags.GetString("notification-email-server-user")
|
||||
password, _ := flags.GetString("notification-email-server-password")
|
||||
port, _ := flags.GetInt("notification-email-server-port")
|
||||
@ -70,7 +70,7 @@ func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte {
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
|
||||
|
||||
header := make(map[string]string)
|
||||
header["From"] = e.From
|
||||
header["To"] = e.To
|
@ -7,8 +7,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// Notifier can send log output as notification to admins, with optional batching.
|
||||
type Notifier struct {
|
||||
types []ty.Notifier
|
@ -1,10 +1,10 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
"github.com/johntdyer/slackrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -18,11 +18,11 @@ type slackTypeNotifier struct {
|
||||
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
|
||||
flags := c.PersistentFlags()
|
||||
|
||||
hookURL, _ := flags.GetString("notification-slack-hook-url")
|
||||
hookURL, _ := flags.GetString("notification-slack-hook-url")
|
||||
userName, _ := flags.GetString("notification-slack-identifier")
|
||||
channel, _ := flags.GetString("notification-slack-channel")
|
||||
emoji, _ := flags.GetString("notification-slack-icon-emoji")
|
||||
iconURL, _ := flags.GetString("notification-slack-icon-url")
|
||||
channel, _ := flags.GetString("notification-slack-channel")
|
||||
emoji, _ := flags.GetString("notification-slack-icon-emoji")
|
||||
iconURL, _ := flags.GetString("notification-slack-icon-url")
|
||||
|
||||
n := &slackTypeNotifier{
|
||||
SlackrusHook: slackrus.SlackrusHook{
|
@ -1,5 +1,6 @@
|
||||
package types
|
||||
|
||||
// Notifier is the interface that all notification services have in common
|
||||
type Notifier interface {
|
||||
StartNotification()
|
||||
SendNotification()
|
||||
|
Loading…
Reference in New Issue
Block a user