Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken tests #929

Merged
merged 3 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/docker/docker v0.0.0-20190404075923-dbe4a30928d4
github.com/docker/docker-credential-helpers v0.6.1 // indirect
github.com/docker/go v1.5.1-1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-connections v0.4.0
github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions internal/actions/mocks/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/containrrr/watchtower/pkg/container"
"github.com/docker/docker/api/types"
container2 "github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"time"
)

Expand All @@ -19,6 +20,7 @@ func CreateMockContainer(id string, name string, image string, created time.Time
Config: &container2.Config{
Image: image,
Labels: make(map[string]string),
ExposedPorts: map[nat.Port]struct{}{},
},
}
return *container.NewContainer(
Expand Down
13 changes: 13 additions & 0 deletions pkg/container/container_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package container_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestContainer(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Container Suite")
}
5 changes: 0 additions & 5 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ func (metrics *Metrics) QueueIsEmpty() bool {
return len(metrics.channel) == 0
}

// QueueIsEmpty checks whether any messages are enqueued in the channel
func (metrics *Metrics) QueueIsEmpty() bool {
return len(metrics.channel) == 0
}

// Register registers metrics for an executed scan
func (metrics *Metrics) Register(metric *Metric) {
metrics.channel <- metric
Expand Down
26 changes: 20 additions & 6 deletions pkg/notifications/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("notifications", func() {
token := "abvsihdbau"
color := notifications.ColorInt
title := url.QueryEscape(notifications.GetTitle())
expected := fmt.Sprintf("discord://%s@%s?avatar=&color=0x%x&colordebug=0x0&colorerror=0x0&colorinfo=0x0&colorwarn=0x0&splitlines=Yes&title=%s&username=watchtower", token, channel, color, title)
expected := fmt.Sprintf("discord://%s@%s?color=0x%x&colordebug=0x0&colorerror=0x0&colorinfo=0x0&colorwarn=0x0&splitlines=Yes&title=%s&username=watchtower", token, channel, color, title)
buildArgs := func(url string) []string {
return []string{
"--notifications",
Expand Down Expand Up @@ -101,7 +101,7 @@ var _ = Describe("notifications", func() {
host := "shoutrrr.local"
title := url.QueryEscape(notifications.GetTitle())

expectedOutput := fmt.Sprintf("gotify://%s/%s?disabletls=No&priority=0&title=%s", host, token, title)
expectedOutput := fmt.Sprintf("gotify://%s/%s?title=%s", host, token, title)

args := []string{
"--notification-gotify-url",
Expand All @@ -128,7 +128,7 @@ var _ = Describe("notifications", func() {
title := url.QueryEscape(notifications.GetTitle())

hookURL := fmt.Sprintf("https://outlook.office.com/webhook/%s/IncomingWebhook/%s/%s", tokenA, tokenB, tokenC)
expectedOutput := fmt.Sprintf("teams://%s/%s/%s?color=%s&host=outlook.office.com&title=%s", tokenA, tokenB, tokenC, color, title)
expectedOutput := fmt.Sprintf("teams://%s/%s/%s?color=%s&title=%s", tokenA, tokenB, tokenC, color, title)

args := []string{
"--notification-msteams-hook",
Expand All @@ -147,10 +147,18 @@ var _ = Describe("notifications", func() {
When("converting an email service config into a shoutrrr url", func() {
It("should set the from address in the URL", func() {
fromAddress := "[email protected]"
expectedOutput := buildExpectedURL("", "", "", 25, fromAddress, "", "None")
expectedOutput := buildExpectedURL("containrrrbot", "secret-password", "mail.containrrr.dev", 25, fromAddress, "[email protected]", "Plain")
args := []string{
"--notification-email-from",
fromAddress,
"--notification-email-to",
"[email protected]",
"--notification-email-server-user",
"containrrrbot",
"--notification-email-server-password",
"secret-password",
"--notification-email-server",
"mail.containrrr.dev",
}
testURL(builderFn, args, expectedOutput)
})
Expand All @@ -159,13 +167,19 @@ var _ = Describe("notifications", func() {

fromAddress := "[email protected]"
toAddress := "[email protected]"
expectedOutput := buildExpectedURL("", "", "", 25, fromAddress, toAddress, "None")
expectedOutput := buildExpectedURL("containrrrbot", "secret-password", "mail.containrrr.dev", 25, fromAddress, toAddress, "Plain")

args := []string{
"--notification-email-from",
fromAddress,
"--notification-email-to",
toAddress,
"--notification-email-server-user",
"containrrrbot",
"--notification-email-server-password",
"secret-password",
"--notification-email-server",
"mail.containrrr.dev",
}

testURL(builderFn, args, expectedOutput)
Expand All @@ -180,7 +194,7 @@ func buildExpectedURL(username string, password string, host string, port int, f

subject := fmt.Sprintf("Watchtower updates on %s", hostname)

var template = "smtp://%s:%s@%s:%d/?auth=%s&encryption=Auto&fromaddress=%s&fromname=Watchtower&starttls=Yes&subject=%s&toaddresses=%s&usehtml=No"
var template = "smtp://%s:%s@%s:%d/?auth=%s&fromaddress=%s&fromname=Watchtower&subject=%s&toaddresses=%s"
return fmt.Sprintf(template,
url.QueryEscape(username),
url.QueryEscape(password),
Expand Down