diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 3bb7d8a9..84a74222 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 - uses: actions/checkout@v3 with: persist-credentials: false @@ -21,6 +21,6 @@ jobs: go generate ./... - uses: golangci/golangci-lint-action@v3 with: - version: v1.47 + version: v1.48 skip-pkg-cache: true skip-build-cache: true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2324c05c..016a4375 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,7 +18,7 @@ jobs: ${{ runner.os }}-go- - uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 - uses: actions/checkout@v3 with: persist-credentials: false diff --git a/.golangci.yaml b/.golangci.yaml index f23c990e..6836d840 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -19,14 +19,15 @@ issues: linters: enable-all: true disable: - - exhaustivestruct # deprecated - - golint # deprecated + - exhaustivestruct # deprecated; replaced by exhaustruct + - golint # deprecated; replaced by revive + - ifshort # deprecated - interfacer # deprecated - ireturn # ireturn works poorly for the style with private types and public interfaces - maligned # deprecated, and I value readability over bytes saved by alignment - - scopelint # deprecated - nlreturn # I don't agree with the style enforced by nlreturn + - nonamedreturns # named returns are needed in the internal updator package + - nosnakecase # revive's var-naming check seems to be better + - scopelint # deprecated; replaced by exportloopref - varnamelen # varnamelen complains too much, in my opinion - wsl # I don't agree with the style enforced by wsl - - nosnakecase # revive's var-naming check seems to be better - - nonamedreturns # named returns are needed in the internal updator package diff --git a/go.mod b/go.mod index 9c3b76f8..75a1fd3b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/favonia/cloudflare-ddns -go 1.18 +go 1.19 require ( github.com/cloudflare/cloudflare-go v0.46.0 diff --git a/internal/api/domain.go b/internal/api/domain.go index cf321ef3..4ec28c1e 100644 --- a/internal/api/domain.go +++ b/internal/api/domain.go @@ -7,9 +7,10 @@ import ( "golang.org/x/net/idna" ) -//nolint:gochecknoglobals -// profile does C2 in UTS#46 with all checks on + removing leading dots. +// profileDroppingLeadingDots does C2 in UTS#46 with all checks on + removing leading dots. // This is the main conversion profile in use. +// +//nolint:gochecknoglobals var ( profileDroppingLeadingDots = idna.New( idna.MapForLookup(), diff --git a/internal/config/config.go b/internal/config/config.go index 638443cf..735ed2bb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -201,7 +201,7 @@ func (c *Config) Print(ppfmt pp.PP) { if len(c.Monitors) > 0 { ppfmt.Infof(pp.EmojiConfig, "Monitors:") for _, m := range c.Monitors { - inner.Infof(pp.EmojiBullet, "%-17s %v", m.DescribeService()+":", m.DescribeBaseURL()) + inner.Infof(pp.EmojiBullet, "%-17s (URL redacted)", m.DescribeService()+":") } } else { ppfmt.Infof(pp.EmojiConfig, "Monitors: (none)") diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 67204d3c..08a24b60 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -337,7 +337,7 @@ func Some(xs ...interface{}) gomock.Matcher { return someMatcher{ms} } -//nolint: paralleltest // changing the environment variable TZ +//nolint:paralleltest // changing the environment variable TZ func TestPrintDefault(t *testing.T) { mockCtrl := gomock.NewController(t) @@ -372,7 +372,7 @@ func TestPrintDefault(t *testing.T) { config.Default().Print(mockPP) } -//nolint: paralleltest // changing the environment variable TZ +//nolint:paralleltest // changing the environment variable TZ func TestPrintEmpty(t *testing.T) { mockCtrl := gomock.NewController(t) @@ -406,7 +406,7 @@ func TestPrintEmpty(t *testing.T) { cfg.Print(mockPP) } -//nolint: paralleltest // changing the environment variable TZ +//nolint:paralleltest // changing the environment variable TZ func TestPrintMonitors(t *testing.T) { mockCtrl := gomock.NewController(t) @@ -439,7 +439,7 @@ func TestPrintMonitors(t *testing.T) { innerMockPP.EXPECT().Infof(pp.EmojiBullet, "IP detection: %v", time.Second*5), innerMockPP.EXPECT().Infof(pp.EmojiBullet, "Record updating: %v", time.Second*30), mockPP.EXPECT().Infof(pp.EmojiConfig, "Monitors:"), - innerMockPP.EXPECT().Infof(pp.EmojiBullet, "%-17s %v", "Healthchecks.io:", "http://user:xxxxx@host/path"), + innerMockPP.EXPECT().Infof(pp.EmojiBullet, "%-17s (URL redacted)", "Healthchecks.io:"), ) m, ok := monitor.NewHealthChecks(mockPP, "http://user:pass@host/path") diff --git a/internal/config/env.go b/internal/config/env.go index 3fe8f044..7bfced7c 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -106,7 +106,8 @@ func ReadDomains(ppfmt pp.PP, key string, field *[]api.Domain) bool { // ReadProvider reads an environment variable and parses it as a provider. // // policyKey was the name of the deprecated parameters IP4/6_POLICY. -//nolint: funlen, cyclop +// +//nolint:funlen, cyclop func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provider) bool { if val := Getenv(key); val == "" { // parsing of the deprecated parameter @@ -117,7 +118,7 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid case "cloudflare": ppfmt.Warningf( pp.EmojiUserWarning, - `Both the parameter %s and the provider "cloudflare" were deprecated; use %s=cloudflare.doh or %s=cloudflare.trace instead.`, //nolint: lll + `Both the parameter %s and the provider "cloudflare" were deprecated; use %s=cloudflare.doh or %s=cloudflare.trace instead.`, //nolint:lll keyDeprecated, key, key, ) *field = provider.NewCloudflareTrace() @@ -180,7 +181,7 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid case "cloudflare": ppfmt.Errorf( pp.EmojiUserError, - `The parameter %s does not accept the provider "cloudflare"; use "cloudflare.doh" or "cloudflare.trace" instead.`, //nolint: lll + `The parameter %s does not accept the provider "cloudflare"; use "cloudflare.doh" or "cloudflare.trace" instead.`, //nolint:lll key, key, ) return false diff --git a/internal/config/env_test.go b/internal/config/env_test.go index a2fcb536..230d56c3 100644 --- a/internal/config/env_test.go +++ b/internal/config/env_test.go @@ -1,6 +1,7 @@ package config_test import ( + "net/url" "os" "testing" "time" @@ -340,7 +341,7 @@ func TestReadProvider(t *testing.T) { func(m *mocks.MockPP) { m.EXPECT().Warningf( pp.EmojiUserWarning, - `Both the parameter %s and the provider "cloudflare" were deprecated; use %s=cloudflare.doh or %s=cloudflare.trace instead.`, //nolint: lll + `Both the parameter %s and the provider "cloudflare" were deprecated; use %s=cloudflare.doh or %s=cloudflare.trace instead.`, //nolint:lll keyDeprecated, key, key, ) }, @@ -431,7 +432,7 @@ func TestReadProvider(t *testing.T) { func(m *mocks.MockPP) { m.EXPECT().Errorf( pp.EmojiUserError, - `The parameter %s does not accept the provider "cloudflare"; use "cloudflare.doh" or "cloudflare.trace" instead.`, //nolint: lll + `The parameter %s does not accept the provider "cloudflare"; use "cloudflare.doh" or "cloudflare.trace" instead.`, //nolint:lll key, key, ) }, @@ -584,6 +585,13 @@ func TestReadCron(t *testing.T) { } } +func urlMustParse(t *testing.T, u string) *url.URL { + t.Helper() + url, err := url.Parse(u) + require.Nil(t, err) + return url +} + //nolint:paralleltest,funlen // paralleltest should not be used because environment vars are global func TestReadHealthChecksURL(t *testing.T) { key := keyPrefix + "HEALTHCHECKS" @@ -608,10 +616,9 @@ func TestReadHealthChecksURL(t *testing.T) { true, "https://hi.org/1234", []mon{}, []mon{&monitor.HealthChecks{ - BaseURL: "https://hi.org/1234", - RedactedBaseURL: "https://hi.org/1234", - Timeout: monitor.HealthChecksDefaultTimeout, - MaxRetries: monitor.HealthChecksDefaultMaxRetries, + BaseURL: urlMustParse(t, "https://hi.org/1234"), + Timeout: monitor.HealthChecksDefaultTimeout, + MaxRetries: monitor.HealthChecksDefaultMaxRetries, }}, true, nil, @@ -620,30 +627,34 @@ func TestReadHealthChecksURL(t *testing.T) { true, "https://me:pass@hi.org/1234", []mon{}, []mon{&monitor.HealthChecks{ - BaseURL: "https://me:pass@hi.org/1234", - RedactedBaseURL: "https://me:xxxxx@hi.org/1234", - Timeout: monitor.HealthChecksDefaultTimeout, - MaxRetries: monitor.HealthChecksDefaultMaxRetries, + BaseURL: urlMustParse(t, "https://me:pass@hi.org/1234"), + Timeout: monitor.HealthChecksDefaultTimeout, + MaxRetries: monitor.HealthChecksDefaultMaxRetries, }}, true, nil, }, - "illformed": { - true, "https://hi.org/1234?hello=123", + "fragment": { + true, "https://hi.org/1234#fragment", []mon{}, + []mon{&monitor.HealthChecks{ + BaseURL: urlMustParse(t, "https://hi.org/1234#fragment"), + Timeout: monitor.HealthChecksDefaultTimeout, + MaxRetries: monitor.HealthChecksDefaultMaxRetries, + }}, + true, + nil, + }, + "query": { + true, "https://hi.org/1234?hello=123", []mon{}, - false, - func(m *mocks.MockPP) { - m.EXPECT().Errorf( - pp.EmojiUserError, - "The URL %q does not look like a valid Healthchecks URL.", - "https://hi.org/1234?hello=123", - ) - m.EXPECT().Errorf( - pp.EmojiUserError, - `A valid example is "https://hc-ping.com/01234567-0123-0123-0123-0123456789abc".`, - ) - }, + []mon{&monitor.HealthChecks{ + BaseURL: urlMustParse(t, "https://hi.org/1234?hello=123"), + Timeout: monitor.HealthChecksDefaultTimeout, + MaxRetries: monitor.HealthChecksDefaultMaxRetries, + }}, + true, + nil, }, } { tc := tc diff --git a/internal/monitor/base.go b/internal/monitor/base.go index c7f6873b..6a8dc3b1 100644 --- a/internal/monitor/base.go +++ b/internal/monitor/base.go @@ -10,7 +10,6 @@ import ( type Monitor interface { DescribeService() string - DescribeBaseURL() string Success(context.Context, pp.PP) bool Start(context.Context, pp.PP) bool Failure(context.Context, pp.PP) bool diff --git a/internal/monitor/healthchecks.go b/internal/monitor/healthchecks.go index cc546dec..4bd0c257 100644 --- a/internal/monitor/healthchecks.go +++ b/internal/monitor/healthchecks.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "net/url" + "strconv" "strings" "time" @@ -13,10 +14,9 @@ import ( ) type HealthChecks struct { - BaseURL string - RedactedBaseURL string - Timeout time.Duration - MaxRetries int + BaseURL *url.URL + Timeout time.Duration + MaxRetries int } const ( @@ -38,21 +38,20 @@ func SetHealthChecksMaxRetries(maxRetries int) HealthChecksOption { func NewHealthChecks(ppfmt pp.PP, rawURL string, os ...HealthChecksOption) (Monitor, bool) { url, err := url.Parse(rawURL) if err != nil { - ppfmt.Errorf(pp.EmojiUserError, "Failed to parse the Healthchecks URL %q: %v", rawURL, err) + ppfmt.Errorf(pp.EmojiUserError, "Failed to parse the Healthchecks.io URL (redacted).") return nil, false } - if !(url.IsAbs() && url.Opaque == "" && url.Host != "" && url.Fragment == "" && !url.ForceQuery && url.RawQuery == "") { //nolint: lll - ppfmt.Errorf(pp.EmojiUserError, `The URL %q does not look like a valid Healthchecks URL.`, url.Redacted()) + if !(url.IsAbs() && url.Opaque == "" && url.Host != "") { + ppfmt.Errorf(pp.EmojiUserError, `The Healthchecks.io URL (redacted) does not look like a valid URL.`) ppfmt.Errorf(pp.EmojiUserError, `A valid example is "https://hc-ping.com/01234567-0123-0123-0123-0123456789abc".`) return nil, false } h := &HealthChecks{ - BaseURL: url.String(), - RedactedBaseURL: url.Redacted(), - Timeout: HealthChecksDefaultTimeout, - MaxRetries: HealthChecksDefaultMaxRetries, + BaseURL: url, + Timeout: HealthChecksDefaultTimeout, + MaxRetries: HealthChecksDefaultMaxRetries, } for _, o := range os { @@ -66,12 +65,15 @@ func (h *HealthChecks) DescribeService() string { return "Healthchecks.io" } -func (h *HealthChecks) DescribeBaseURL() string { - return h.RedactedBaseURL -} +//nolint:funlen +func (h *HealthChecks) ping(ctx context.Context, ppfmt pp.PP, endpoint string) bool { + url := h.BaseURL.JoinPath(endpoint) + + endpointDescription := "default (root)" + if endpoint != "" { + endpointDescription = strconv.Quote(endpoint) + } -//nolint: funlen -func (h *HealthChecks) ping(ctx context.Context, ppfmt pp.PP, url string, redatedURL string) bool { for retries := 0; retries < h.MaxRetries; retries++ { if retries > 0 { time.Sleep(time.Second << (retries - 1)) @@ -80,22 +82,28 @@ func (h *HealthChecks) ping(ctx context.Context, ppfmt pp.PP, url string, redate ctx, cancel := context.WithTimeout(ctx, h.Timeout) defer cancel() - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil) if err != nil { - ppfmt.Warningf(pp.EmojiImpossible, "Failed to prepare HTTP(S) request to %q: %v", redatedURL, err) + ppfmt.Warningf(pp.EmojiImpossible, + "Failed to prepare HTTP(S) request to the %s endpoint of Healthchecks.io: %v", + endpointDescription, err) return false } resp, err := http.DefaultClient.Do(req) if err != nil { - ppfmt.Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", redatedURL, err) + ppfmt.Warningf(pp.EmojiError, + "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", + endpointDescription, err) ppfmt.Infof(pp.EmojiRepeatOnce, "Trying again . . .") continue } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - ppfmt.Warningf(pp.EmojiError, "Failed to read HTTP(S) response from %q: %v", redatedURL, err) + ppfmt.Warningf(pp.EmojiError, + "Failed to read HTTP(S) response from the %s endpoint of Healthchecks.io: %v", + endpointDescription, err) ppfmt.Infof(pp.EmojiRepeatOnce, "Trying again . . .") continue } @@ -119,34 +127,34 @@ func (h *HealthChecks) ping(ctx context.Context, ppfmt pp.PP, url string, redate bodyAsString := strings.TrimSpace(string(body)) if bodyAsString != "OK" { - ppfmt.Warningf( - pp.EmojiError, - "Failed to ping %q; got response code: %d %s", - redatedURL, - resp.StatusCode, - bodyAsString, + ppfmt.Warningf(pp.EmojiError, + "Failed to ping the %s endpoint of Healthchecks.io; got response code: %d %s", + endpointDescription, resp.StatusCode, bodyAsString, ) return false } - ppfmt.Infof(pp.EmojiNotification, "Successfully pinged %q.", redatedURL) + ppfmt.Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", endpointDescription) return true } - ppfmt.Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q in %d time(s).", redatedURL, h.MaxRetries) + ppfmt.Warningf( + pp.EmojiError, + "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io in %d time(s).", + endpointDescription, h.MaxRetries) return false } func (h *HealthChecks) Success(ctx context.Context, ppfmt pp.PP) bool { - return h.ping(ctx, ppfmt, h.BaseURL, h.RedactedBaseURL) + return h.ping(ctx, ppfmt, "") } func (h *HealthChecks) Start(ctx context.Context, ppfmt pp.PP) bool { - return h.ping(ctx, ppfmt, h.BaseURL+"/start", h.RedactedBaseURL+"/start") + return h.ping(ctx, ppfmt, "/start") } func (h *HealthChecks) Failure(ctx context.Context, ppfmt pp.PP) bool { - return h.ping(ctx, ppfmt, h.BaseURL+"/fail", h.RedactedBaseURL+"/fail") + return h.ping(ctx, ppfmt, "/fail") } func (h *HealthChecks) ExitStatus(ctx context.Context, ppfmt pp.PP, code int) bool { @@ -155,5 +163,5 @@ func (h *HealthChecks) ExitStatus(ctx context.Context, ppfmt pp.PP, code int) bo return false } - return h.ping(ctx, ppfmt, fmt.Sprintf("%s/%d", h.BaseURL, code), fmt.Sprintf("%s/%d", h.RedactedBaseURL, code)) + return h.ping(ctx, ppfmt, fmt.Sprintf("/%d", code)) } diff --git a/internal/monitor/healthchecks_test.go b/internal/monitor/healthchecks_test.go index 36ce78cf..d63bf170 100644 --- a/internal/monitor/healthchecks_test.go +++ b/internal/monitor/healthchecks_test.go @@ -19,11 +19,11 @@ import ( func TestSetHealthChecksMaxRetries(t *testing.T) { t.Parallel() - m := &monitor.HealthChecks{} //nolint: exhaustruct + m := &monitor.HealthChecks{} //nolint:exhaustruct monitor.SetHealthChecksMaxRetries(42)(m) - require.Equal(t, m, &monitor.HealthChecks{MaxRetries: 42}) //nolint: exhaustruct + require.Equal(t, m, &monitor.HealthChecks{MaxRetries: 42}) //nolint:exhaustruct } func TestSetHealthChecksMaxRetriesPanic(t *testing.T) { @@ -44,14 +44,17 @@ func TestSetHealthChecksMaxRetriesPanic(t *testing.T) { func TestNewHealthChecks(t *testing.T) { t.Parallel() + rawURL := "https://user:pass@host/path" + parsedURL, err := url.Parse(rawURL) + require.NoError(t, err) + mockCtrl := gomock.NewController(t) mockPP := mocks.NewMockPP(mockCtrl) - m, ok := monitor.NewHealthChecks(mockPP, "https://user:pass@host/path", monitor.SetHealthChecksMaxRetries(100)) + m, ok := monitor.NewHealthChecks(mockPP, rawURL, monitor.SetHealthChecksMaxRetries(100)) require.Equal(t, m, &monitor.HealthChecks{ - BaseURL: "https://user:pass@host/path", - RedactedBaseURL: "https://user:xxxxx@host/path", - Timeout: monitor.HealthChecksDefaultTimeout, - MaxRetries: 100, + BaseURL: parsedURL, + Timeout: monitor.HealthChecksDefaultTimeout, + MaxRetries: 100, }) require.True(t, ok) } @@ -62,8 +65,8 @@ func TestNewHealthChecksFail1(t *testing.T) { mockCtrl := gomock.NewController(t) mockPP := mocks.NewMockPP(mockCtrl) gomock.InOrder( - mockPP.EXPECT().Errorf(pp.EmojiUserError, `The URL %q does not look like a valid Healthchecks URL.`, url.PathEscape("this is not a valid URL")), //nolint: lll - mockPP.EXPECT().Errorf(pp.EmojiUserError, `A valid example is "https://hc-ping.com/01234567-0123-0123-0123-0123456789abc".`), //nolint: lll + mockPP.EXPECT().Errorf(pp.EmojiUserError, `The Healthchecks.io URL (redacted) does not look like a valid URL.`), + mockPP.EXPECT().Errorf(pp.EmojiUserError, `A valid example is "https://hc-ping.com/01234567-0123-0123-0123-0123456789abc".`), //nolint:lll ) _, ok := monitor.NewHealthChecks(mockPP, "this is not a valid URL") require.False(t, ok) @@ -74,7 +77,7 @@ func TestNewHealthChecksFail2(t *testing.T) { mockCtrl := gomock.NewController(t) mockPP := mocks.NewMockPP(mockCtrl) - mockPP.EXPECT().Errorf(pp.EmojiUserError, "Failed to parse the Healthchecks URL %q: %v", "://#?", gomock.Any()) + mockPP.EXPECT().Errorf(pp.EmojiUserError, "Failed to parse the Healthchecks.io URL (redacted).") _, ok := monitor.NewHealthChecks(mockPP, "://#?") require.False(t, ok) } @@ -89,17 +92,7 @@ func TestDescripbeService(t *testing.T) { require.Equal(t, "Healthchecks.io", m.DescribeService()) } -func TestDescripbeBaseURL(t *testing.T) { - t.Parallel() - - mockCtrl := gomock.NewController(t) - mockPP := mocks.NewMockPP(mockCtrl) - m, ok := monitor.NewHealthChecks(mockPP, "https://user:pass@host/path") - require.True(t, ok) - require.Equal(t, "https://user:xxxxx@host/path", m.DescribeBaseURL()) -} - -//nolint: funlen +//nolint:funlen func TestEndPoints(t *testing.T) { t.Parallel() @@ -128,11 +121,11 @@ func TestEndPoints(t *testing.T) { true, true, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged %q.", gomock.Any()), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", `default (root)`), //nolint:lll ) }, }, @@ -145,11 +138,11 @@ func TestEndPoints(t *testing.T) { false, false, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to ping %q; got response code: %d %s", gomock.Any(), 400, "invalid url format"), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to ping the %s endpoint of Healthchecks.io; got response code: %d %s", `default (root)`, 400, "invalid url format"), //nolint:lll ) }, }, @@ -162,13 +155,13 @@ func TestEndPoints(t *testing.T) { false, false, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q in %d time(s).", gomock.Any(), 3), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `default (root)`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io in %d time(s).", `default (root)`, 3), //nolint:lll ) }, }, @@ -181,11 +174,11 @@ func TestEndPoints(t *testing.T) { true, true, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged %q.", gomock.Any()), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/start"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/start"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", `"/start"`), //nolint:lll ) }, }, @@ -198,11 +191,11 @@ func TestEndPoints(t *testing.T) { true, true, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged %q.", gomock.Any()), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/fail"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/fail"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", `"/fail"`), //nolint:lll ) }, }, @@ -215,11 +208,11 @@ func TestEndPoints(t *testing.T) { true, true, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged %q.", gomock.Any()), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/0"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/0"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", `"/0"`), //nolint:lll ) }, }, @@ -232,11 +225,11 @@ func TestEndPoints(t *testing.T) { true, true, func(m *mocks.MockPP) { gomock.InOrder( - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to %q: %v", gomock.Any(), gomock.Any()), //nolint: lll - m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint: lll - m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged %q.", gomock.Any()), //nolint: lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/1"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Warningf(pp.EmojiError, "Failed to send HTTP(S) request to the %s endpoint of Healthchecks.io: %v", `"/1"`, gomock.Any()), //nolint:lll + m.EXPECT().Infof(pp.EmojiRepeatOnce, "Trying again . . ."), //nolint:lll + m.EXPECT().Infof(pp.EmojiNotification, "Successfully pinged the %s endpoint of Healthchecks.io.", `"/1"`), //nolint:lll ) }, }, @@ -295,20 +288,3 @@ func TestEndPoints(t *testing.T) { }) } } - -func TestEndPointsIllFormed(t *testing.T) { - t.Parallel() - mockCtrl := gomock.NewController(t) - mockPP := mocks.NewMockPP(mockCtrl) - mockPP.EXPECT().Warningf(pp.EmojiImpossible, "Failed to prepare HTTP(S) request to %q: %v", "blah", gomock.Any()) - - m := &monitor.HealthChecks{ - BaseURL: "://#?", - RedactedBaseURL: "blah", - Timeout: monitor.HealthChecksDefaultTimeout, - MaxRetries: monitor.HealthChecksDefaultMaxRetries, - } - - ok := m.Success(context.Background(), mockPP) - require.False(t, ok) -} diff --git a/internal/setter/setter.go b/internal/setter/setter.go index ffdfea27..6da7f2f8 100644 --- a/internal/setter/setter.go +++ b/internal/setter/setter.go @@ -49,8 +49,8 @@ func New(_ppfmt pp.PP, handle api.Handle, ttl api.TTL, proxied bool) (Setter, bo }, true } -//nolint: funlen,cyclop,gocognit -func (s *setter) Set(ctx context.Context, ppfmt pp.PP, domain api.Domain, ipnet ipnet.Type, ip netip.Addr) bool { //nolint: lll +//nolint:funlen,cyclop,gocognit +func (s *setter) Set(ctx context.Context, ppfmt pp.PP, domain api.Domain, ipnet ipnet.Type, ip netip.Addr) bool { //nolint:lll recordType := ipnet.RecordType() domainDescription := domain.Describe()