Skip to content

Commit

Permalink
test(monitor): fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Oct 15, 2023
1 parent 987b43f commit f75e5c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 0 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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!
</details>

### 🔂 Restarting the Container
Expand Down
12 changes: 7 additions & 5 deletions internal/monitor/updatekuma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions internal/monitor/updatekuma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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) {
m.EXPECT().Warningf(pp.EmojiUserError, "The Uptime Kuma URL (redacted) contains an unexpected query %s=... and it will not be used", "random") //nolint:lll
},
},
"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")
},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit f75e5c5

Please sign in to comment.