fix: skip integration tests without telegram secrets; apply modernize fix

This commit is contained in:
Bo-Yi Wu
2026-04-16 22:39:48 +08:00
parent 7007692d2e
commit cff7d4e183
2 changed files with 16 additions and 3 deletions
+2 -3
View File
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"html" "html"
"log" "log"
"maps"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@@ -307,9 +308,7 @@ func (p *Plugin) Exec() (err error) {
if p.Tpl == nil { if p.Tpl == nil {
p.Tpl = vars p.Tpl = vars
} else { } else {
for k, v := range vars { maps.Copy(p.Tpl, vars)
p.Tpl[k] = v
}
} }
} }
+14
View File
@@ -10,6 +10,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func skipIfNoTelegramSecrets(t *testing.T) {
t.Helper()
if os.Getenv("TELEGRAM_TOKEN") == "" || os.Getenv("TELEGRAM_TO") == "" {
t.Skip("TELEGRAM_TOKEN/TELEGRAM_TO not set; skipping integration test")
}
}
func TestMissingDefaultConfig(t *testing.T) { func TestMissingDefaultConfig(t *testing.T) {
var plugin Plugin var plugin Plugin
@@ -148,6 +155,7 @@ func TestSendMessage(t *testing.T) {
} }
func TestDisableWebPagePreviewMessage(t *testing.T) { func TestDisableWebPagePreviewMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Config: Config{ Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"), Token: os.Getenv("TELEGRAM_TOKEN"),
@@ -169,6 +177,7 @@ func TestDisableWebPagePreviewMessage(t *testing.T) {
} }
func TestDisableNotificationMessage(t *testing.T) { func TestDisableNotificationMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Config: Config{ Config: Config{
Token: os.Getenv("TELEGRAM_TOKEN"), Token: os.Getenv("TELEGRAM_TOKEN"),
@@ -365,6 +374,7 @@ func TestConvertLocation(t *testing.T) {
} }
func TestHTMLMessage(t *testing.T) { func TestHTMLMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Name: "go-hello", Name: "go-hello",
@@ -402,6 +412,7 @@ Test HTML Format
} }
func TestMessageFile(t *testing.T) { func TestMessageFile(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Name: "go-hello", Name: "go-hello",
@@ -433,6 +444,7 @@ func TestMessageFile(t *testing.T) {
} }
func TestTemplateVars(t *testing.T) { func TestTemplateVars(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Name: "go-hello", Name: "go-hello",
@@ -466,6 +478,7 @@ func TestTemplateVars(t *testing.T) {
} }
func TestTemplateVarsFile(t *testing.T) { func TestTemplateVarsFile(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Name: "go-hello", Name: "go-hello",
@@ -497,6 +510,7 @@ func TestTemplateVarsFile(t *testing.T) {
} }
func TestProxySendMessage(t *testing.T) { func TestProxySendMessage(t *testing.T) {
skipIfNoTelegramSecrets(t)
plugin := Plugin{ plugin := Plugin{
Repo: Repo{ Repo: Repo{
Name: "go-hello", Name: "go-hello",