From f75e5c59f534dfddd98c881a116082fbb3f14bb8 Mon Sep 17 00:00:00 2001 From: favonia Date: Sun, 15 Oct 2023 00:22:09 -0500 Subject: [PATCH] test(monitor): fix test cases --- README.markdown | 2 -- internal/monitor/updatekuma.go | 12 +++++++----- internal/monitor/updatekuma_test.go | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.markdown b/README.markdown index b9fd0ec5..c54a6bfb 100644 --- a/README.markdown +++ b/README.markdown @@ -338,8 +338,6 @@ _(Click to expand the following items.)_ > 🩺 For `HEALTHCHECKS`, the updater can work with any server following the [same notification protocol](https://healthchecks.io/docs/http_api/), including but not limited to self-hosted instances of [Healthchecks](https://github.com/healthchecks/healthchecks). Both UUID and Slug URLs are supported, and the updater works regardless whether the POST-only mode is enabled. -> 🐻 For `UPTIMEKUMA` (Uptime Kuma), it seems the service can only display the first success message. This means the detailed information of follow-up operations will not be shown in Uptime Kuma. If you find this confusing, or if you have suggestions about how to work around this limitation, please [open a GitHub issue.](https://github.com/favonia/cloudflare-ddns/issues/new) Thank you! - ### 🔂 Restarting the Container diff --git a/internal/monitor/updatekuma.go b/internal/monitor/updatekuma.go index b0ca33f1..de1edba9 100644 --- a/internal/monitor/updatekuma.go +++ b/internal/monitor/updatekuma.go @@ -148,9 +148,11 @@ func (h *UptimeKuma) ping(ctx context.Context, ppfmt pp.PP, param UptimeKumaRequ return true } -// Success pings the server with status=up. -func (h *UptimeKuma) Success(ctx context.Context, ppfmt pp.PP, message string) bool { - return h.ping(ctx, ppfmt, UptimeKumaRequest{Status: "up", Msg: message, Ping: ""}) +// Success pings the server with status=up. Messages are ignored and "OK" is used instead. +// The reason is that Uptime Kuma seems to show only the first success message +// and it could be misleading if an outdated message stays in the UI. +func (h *UptimeKuma) Success(ctx context.Context, ppfmt pp.PP, _message string) bool { + return h.ping(ctx, ppfmt, UptimeKumaRequest{Status: "up", Msg: "OK", Ping: ""}) } // Start does nothing. @@ -168,10 +170,10 @@ func (h *UptimeKuma) Log(ctx context.Context, ppfmt pp.PP, message string) bool return true } -// ExitStatus does nothing. +// ExitStatus with non-zero triggers [Failure]. Otherwise, it does nothing. func (h *UptimeKuma) ExitStatus(ctx context.Context, ppfmt pp.PP, code int, message string) bool { if code != 0 { - return h.ping(ctx, ppfmt, UptimeKumaRequest{Status: "down", Msg: message, Ping: ""}) + return h.Failure(ctx, ppfmt, message) } return true } diff --git a/internal/monitor/updatekuma_test.go b/internal/monitor/updatekuma_test.go index 9f74713d..299ab785 100644 --- a/internal/monitor/updatekuma_test.go +++ b/internal/monitor/updatekuma_test.go @@ -29,7 +29,7 @@ func TestNewUptimeKuma(t *testing.T) { prepareMockPP func(*mocks.MockPP) }{ "bare": {"https://user:pass@host/path", true, nil}, - "full": {"https://user:pass@host/path?status=up&msg=Ok&ping=", true, nil}, + "full": {"https://user:pass@host/path?status=up&msg=OK&ping=", true, nil}, "unexpected": { "https://user:pass@host/path?random=", true, func(m *mocks.MockPP) { @@ -37,7 +37,7 @@ func TestNewUptimeKuma(t *testing.T) { }, }, "ill-formed-query": { - "https://user:pass@host/path?status=up;msg=Ok;ping=", false, + "https://user:pass@host/path?status=up;msg=OK;ping=", false, func(m *mocks.MockPP) { m.EXPECT().Errorf(pp.EmojiUserError, "The Uptime Kuma URL (redacted) does not look like a valid URL") }, @@ -113,7 +113,7 @@ func TestUptimeKumaEndPoints(t *testing.T) { func(ppfmt pp.PP, m monitor.Monitor) bool { return m.Success(context.Background(), ppfmt, "hello") }, - "/", "up", "hello", "", + "/", "up", "OK", "", []action{ActionOk}, ActionAbort, true, true, @@ -128,7 +128,7 @@ func TestUptimeKumaEndPoints(t *testing.T) { func(ppfmt pp.PP, m monitor.Monitor) bool { return m.Success(context.Background(), ppfmt, "aloha") }, - "/", "up", "aloha", "", + "/", "up", "OK", "", []action{ActionNotOk}, ActionAbort, false, false, @@ -143,7 +143,7 @@ func TestUptimeKumaEndPoints(t *testing.T) { func(ppfmt pp.PP, m monitor.Monitor) bool { return m.Success(context.Background(), ppfmt, "aloha") }, - "/", "up", "aloha", "", + "/", "up", "OK", "", []action{ActionGarbage}, ActionAbort, false, false, @@ -158,7 +158,7 @@ func TestUptimeKumaEndPoints(t *testing.T) { func(ppfmt pp.PP, m monitor.Monitor) bool { return m.Success(context.Background(), ppfmt, "stop now") }, - "/", "up", "stop now", "", + "/", "up", "OK", "", nil, ActionAbort, false, false, func(m *mocks.MockPP) {