diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go index 8b638ab..78ab25d 100644 --- a/internal/domain/domain_test.go +++ b/internal/domain/domain_test.go @@ -10,6 +10,7 @@ import ( "gabe565.com/domain-watch/internal/config" "gabe565.com/domain-watch/internal/integration" + "gabe565.com/domain-watch/internal/integration/telegram" "github.com/go-telegram/bot" whoisparser "github.com/likexian/whois-parser" "github.com/stretchr/testify/assert" @@ -75,14 +76,14 @@ func TestDomain_NotifyThreshold(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, "/bot123/sendMessage", r.URL.Path) gotNotify = true - resp := integration.APIResponse{ + resp := telegram.APIResponse{ OK: true, Result: json.RawMessage("{}"), } assert.NoError(t, json.NewEncoder(w).Encode(&resp)) })) t.Cleanup(server.Close) - telegram := integration.TelegramTestSetup(t, bot.WithServerURL(server.URL)) + tg := telegram.NewTestClient(t, bot.WithServerURL(server.URL)) d := &Domain{ conf: &config.Config{Threshold: []int{1, 7}}, @@ -93,7 +94,7 @@ func TestDomain_NotifyThreshold(t *testing.T) { TimeLeft: tt.fields.TimeLeft, TriggeredThreshold: tt.fields.TriggeredThreshold, } - tt.wantErr(t, d.NotifyThreshold(context.Background(), integration.Integrations{"telegram": telegram})) + tt.wantErr(t, d.NotifyThreshold(context.Background(), integration.Integrations{"telegram": tg})) assert.Equal(t, tt.wantNotify, gotNotify) }) } @@ -148,14 +149,14 @@ func TestDomain_NotifyStatusChange(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, "/bot123/sendMessage", r.URL.Path) gotNotify = true - resp := integration.APIResponse{ + resp := telegram.APIResponse{ OK: true, Result: json.RawMessage("{}"), } assert.NoError(t, json.NewEncoder(w).Encode(resp)) })) t.Cleanup(server.Close) - telegram := integration.TelegramTestSetup(t, bot.WithServerURL(server.URL)) + tg := telegram.NewTestClient(t, bot.WithServerURL(server.URL)) d := &Domain{ Name: tt.fields.Name, @@ -164,7 +165,7 @@ func TestDomain_NotifyStatusChange(t *testing.T) { TimeLeft: tt.fields.TimeLeft, TriggeredThreshold: tt.fields.TriggeredThreshold, } - tt.wantErr(t, d.NotifyStatusChange(context.Background(), integration.Integrations{"telegram": telegram})) + tt.wantErr(t, d.NotifyStatusChange(context.Background(), integration.Integrations{"telegram": tg})) assert.Equal(t, tt.wantNotify, gotNotify) }) } diff --git a/internal/integration/gotify.go b/internal/integration/gotify/gotify.go similarity index 99% rename from internal/integration/gotify.go rename to internal/integration/gotify/gotify.go index 5695f6e..aabd9cf 100644 --- a/internal/integration/gotify.go +++ b/internal/integration/gotify/gotify.go @@ -1,4 +1,4 @@ -package integration +package gotify import ( "bytes" diff --git a/internal/integration/integration.go b/internal/integration/integration.go index cb7aaa0..5101d65 100644 --- a/internal/integration/integration.go +++ b/internal/integration/integration.go @@ -6,6 +6,8 @@ import ( "log/slog" "gabe565.com/domain-watch/internal/config" + "gabe565.com/domain-watch/internal/integration/gotify" + "gabe565.com/domain-watch/internal/integration/telegram" "gabe565.com/domain-watch/internal/util" ) @@ -18,8 +20,8 @@ type Integrations map[string]Integration func Default() Integrations { return map[string]Integration{ - "telegram": &Telegram{}, - "gotify": &Gotify{}, + "telegram": &telegram.Telegram{}, + "gotify": &gotify.Gotify{}, } } diff --git a/internal/integration/telegram.go b/internal/integration/telegram/telegram.go similarity index 98% rename from internal/integration/telegram.go rename to internal/integration/telegram/telegram.go index f996a7d..ef9d21d 100644 --- a/internal/integration/telegram.go +++ b/internal/integration/telegram/telegram.go @@ -1,4 +1,4 @@ -package integration +package telegram import ( "context" diff --git a/internal/integration/telegram_test_setup.go b/internal/integration/telegram/telegram_test_setup.go similarity index 94% rename from internal/integration/telegram_test_setup.go rename to internal/integration/telegram/telegram_test_setup.go index 2cc19a0..c21c262 100644 --- a/internal/integration/telegram_test_setup.go +++ b/internal/integration/telegram/telegram_test_setup.go @@ -1,4 +1,4 @@ -package integration +package telegram import ( "bytes" @@ -24,7 +24,7 @@ type APIResponse struct { } `json:"parameters,omitempty"` } -func TelegramTestSetup(t *testing.T, opts ...bot.Option) *Telegram { +func NewTestClient(t *testing.T, opts ...bot.Option) *Telegram { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/bot123/getMe" { var buf bytes.Buffer