-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tze Yang Ng
committed
Mar 31, 2024
1 parent
73cdc5e
commit 7b310c2
Showing
12 changed files
with
144 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
Dsn: host=dev-db user=dev password=registrywatcher dbname=registrywatcher port=5432 sslmode=disable | ||
db: | ||
dsn: host=dev-db user=registrywatcher password=4rEKcUsVGE dbname=registrywatcher port=5432 sslmode=disable | ||
docker: | ||
base_url: https://hub.docker.com | ||
username: dsdlocus | ||
|
||
nomad: | ||
base_url: http://localhost:4646 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
db: | ||
dsn: host=test-db user=registrywatcher password=4rEKcUsVGE dbname=registrywatcher port=5432 sslmode=disable | ||
dsn: host=test-db user=registrywatcher password=4rEKcUsVGE dbname=registrywatcher port=5432 sslmode=disable | ||
docker: | ||
base_url: localhost:5000 | ||
username: test | ||
password: test | ||
nomad: | ||
base_url: http://localhost:4646 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fakes | ||
package external | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package external | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/slack-go/slack" | ||
) | ||
|
||
type MessageLevel int | ||
|
||
const ( | ||
Info MessageLevel = iota | ||
Success | ||
Error | ||
) | ||
|
||
type Slack interface { | ||
SendMessage(message string, level MessageLevel) | ||
} | ||
|
||
type SlackClient struct { | ||
webhookURL string | ||
} | ||
|
||
func (client *SlackClient) SendMessage(message string, level MessageLevel) { | ||
slackAttachment := map[MessageLevel]slack.Attachment{ | ||
Info: { | ||
Color: "#FFA500", // Orange | ||
}, | ||
Success: { | ||
Color: "#00FF00", // Green | ||
ThumbURL: "https://i.imgur.com/LWRp6ZT.png", | ||
}, | ||
Error: { | ||
Color: "#FF0000", // Red | ||
ThumbURL: "https://i.imgur.com/MJ5Qx8f.jpg", | ||
}, | ||
}[level] | ||
|
||
slackAttachment.Text = message | ||
|
||
if err := slack.PostWebhook(client.webhookURL, &slack.WebhookMessage{ | ||
Attachments: []slack.Attachment{slackAttachment}, | ||
}); err != nil { | ||
log.Panicln("Failed to send message to Slack:", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package external | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
type FakeSlackClient struct{} | ||
|
||
func (client *FakeSlackClient) SendMessage(message string, level MessageLevel) { | ||
log.Println("Fake Slack message:", message, level) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package external | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestSlackClient_SendMessage_External(t *testing.T) { | ||
if !*external { | ||
t.Skip("skipping test; set -external to run this test") | ||
} | ||
url := os.Getenv("SLACK_WEBHOOK_URL") | ||
if url == "" { | ||
t.Fatal("SLACK_WEBHOOK_URL not set") | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
level MessageLevel | ||
message string | ||
}{ | ||
{ | ||
name: "Test send info message", | ||
level: Info, | ||
message: "test info message", | ||
}, | ||
{ | ||
name: "Test send success message", | ||
level: Success, | ||
message: "test success message", | ||
}, | ||
{ | ||
name: "Test send error message", | ||
level: Error, | ||
message: "test error message", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
client := &SlackClient{ | ||
webhookURL: url, | ||
} | ||
client.SendMessage(tt.message, tt.level) | ||
// Check the Slack channel for the message | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters