Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use Go 1.19 #193

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/api/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions internal/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
59 changes: 35 additions & 24 deletions internal/config/env_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config_test

import (
"net/url"
"os"
"testing"
"time"
Expand Down Expand Up @@ -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,
)
},
Expand Down Expand Up @@ -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,
)
},
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/monitor/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down