Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
package notifications
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuildTelegramURL(t *testing.T) {
tests := []struct {
name string
config TelegramConfig
wantURL string
}{
{
name: "basic config with single chat",
config: TelegramConfig{
BotToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
ChatIDs: []string{"@channel"},
Preview: true,
Notification: true,
},
wantURL: "telegram://123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11@telegram?chats=%40channel",
},
{
name: "config with multiple chats",
config: TelegramConfig{
BotToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
ChatIDs: []string{"@channel1", "123456789"},
Preview: false,
Notification: false,
Title: "Arcane",
},
wantURL: "telegram://123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11@telegram?chats=%40channel1%2C123456789¬ification=No&preview=No&title=Arcane",
},
{
name: "config with title",
config: TelegramConfig{
BotToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
ChatIDs: []string{"@mybot"},
Preview: true,
Notification: true,
Title: "Container Updates",
},
wantURL: "telegram://123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11@telegram?chats=%40mybot&title=Container+Updates",
},
{
name: "config with topic destination",
config: TelegramConfig{
BotToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
ChatIDs: []string{"-1001234567890:42"},
Preview: true,
Notification: true,
},
wantURL: "telegram://123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11@telegram?chats=-1001234567890%3A42",
},
{
name: "config with mixed chat and topic destinations",
config: TelegramConfig{
BotToken: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
ChatIDs: []string{"@channel", "-1001234567890:42", "-1001234567890:7"},
Preview: true,
Notification: true,
},
wantURL: "telegram://123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11@telegram?chats=%40channel%2C-1001234567890%3A42%2C-1001234567890%3A7",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotURL, err := BuildTelegramURL(tt.config)
require.NoError(t, err)
assert.Equal(t, tt.wantURL, gotURL)
})
}
}