diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index b404ce7c7..e887dc5b1 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -26,14 +26,14 @@ jobs: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Install Go - uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0 + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 with: go-version: 1.24.x - name: Install snmp_exporter/generator dependencies run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: args: --verbose - version: v1.64.6 + version: v2.3.0 diff --git a/.golangci.yml b/.golangci.yml index 5bc94b8a5..e6d09880b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,99 +1,96 @@ -output: - sort-results: true - +version: "2" linters: enable: - depguard - errorlint - godot - - gofumpt - - goimports - misspell - revive - - testifylint - sloglint - + - testifylint + settings: + depguard: + rules: + main: + deny: + - pkg: sync/atomic + desc: "Use go.uber.org/atomic instead of sync/atomic" + - pkg: github.com/stretchr/testify/assert + desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" + - pkg: github.com/go-kit/kit/log + desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" + - pkg: github.com/pkg/errors + desc: "Use errors or fmt instead of github.com/pkg/errors" + errcheck: + exclude-functions: + # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". + - io.Copy + # The next two are used in HTTP handlers, any error is handled by the server itself. + - io.WriteString + - (net/http.ResponseWriter).Write + # No need to check for errors on server's shutdown. + - (*net/http.Server).Shutdown + # Never check for rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback + godot: + scope: toplevel + exclude: + - "^ ?This file is safe to edit" + - "^ ?scheme value" + period: true + capital: true + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + arguments: + - disableStutteringCheck + - name: if-return + - name: increment-decrement + - name: indent-error-flow + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: var-declaration + - name: var-naming + testifylint: + disable: + - float-compare + - go-require + enable-all: true + exclusions: + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ + rules: + - linters: + - errcheck + path: _test.go + warn-unused: true issues: max-issues-per-linter: 0 max-same-issues: 0 - exclude-rules: - - path: _test.go - linters: - - errcheck - exclude-files: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ - run: timeout: 5m - -linters-settings: - depguard: - rules: - main: - deny: - - pkg: sync/atomic - desc: "Use go.uber.org/atomic instead of sync/atomic" - - pkg: github.com/stretchr/testify/assert - desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" - - pkg: github.com/go-kit/kit/log - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - - pkg: github.com/pkg/errors - desc: "Use errors or fmt instead of github.com/pkg/errors" - errcheck: - exclude-functions: - # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". - - io.Copy - # The next two are used in HTTP handlers, any error is handled by the server itself. - - io.WriteString - - (net/http.ResponseWriter).Write - # No need to check for errors on server's shutdown. - - (*net/http.Server).Shutdown - # Never check for rollback errors as Rollback() is called when a previous error was detected. - - (github.com/prometheus/prometheus/storage.Appender).Rollback - godot: - scope: toplevel - exclude: - - "^ ?This file is safe to edit" - - "^ ?scheme value" - period: true - capital: true - goimports: - local-prefixes: github.com/prometheus/alertmanager - gofumpt: - extra-rules: true - revive: - rules: - - name: exported - arguments: ["disableStutteringCheck"] - - name: blank-imports - - name: context-as-argument - - name: error-return - - name: error-strings - - name: error-naming - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - testifylint: - disable: - - float-compare - - go-require - enable: - - bool-compare - - compares - - empty - - error-is-as - - error-nil - - expected-actual - - len - - require-error - - suite-dont-use-pkg - - suite-extra-assert-call +formatters: + enable: + - gofumpt + - goimports + settings: + gofumpt: + extra-rules: true + goimports: + local-prefixes: + - github.com/prometheus/alertmanager diff --git a/Makefile.common b/Makefile.common index 8cb383859..09413e86f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v1.64.6 +GOLANGCI_LINT_VERSION ?= v2.3.0 # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) diff --git a/api/v2/api.go b/api/v2/api.go index 0e29375d4..dd0ffd6f6 100644 --- a/api/v2/api.go +++ b/api/v2/api.go @@ -565,16 +565,16 @@ func SortSilences(sils open_api_models.GettableSilences) { } switch state1 { case types.SilenceStateActive: - endsAt1 := time.Time(*sils[i].Silence.EndsAt) - endsAt2 := time.Time(*sils[j].Silence.EndsAt) + endsAt1 := time.Time(*sils[i].EndsAt) + endsAt2 := time.Time(*sils[j].EndsAt) return endsAt1.Before(endsAt2) case types.SilenceStatePending: - startsAt1 := time.Time(*sils[i].Silence.StartsAt) - startsAt2 := time.Time(*sils[j].Silence.StartsAt) + startsAt1 := time.Time(*sils[i].StartsAt) + startsAt2 := time.Time(*sils[j].StartsAt) return startsAt1.Before(startsAt2) case types.SilenceStateExpired: - endsAt1 := time.Time(*sils[i].Silence.EndsAt) - endsAt2 := time.Time(*sils[j].Silence.EndsAt) + endsAt1 := time.Time(*sils[i].EndsAt) + endsAt2 := time.Time(*sils[j].EndsAt) return endsAt1.After(endsAt2) } return false diff --git a/cli/format/format_extended.go b/cli/format/format_extended.go index 3870cc7db..3fab403c5 100644 --- a/cli/format/format_extended.go +++ b/cli/format/format_extended.go @@ -48,8 +48,8 @@ func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSil "%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n", *silence.ID, extendedFormatMatchers(silence.Matchers), - FormatDate(*silence.Silence.StartsAt), - FormatDate(*silence.Silence.EndsAt), + FormatDate(*silence.StartsAt), + FormatDate(*silence.EndsAt), FormatDate(*silence.UpdatedAt), *silence.CreatedBy, *silence.Comment, diff --git a/cli/format/sort.go b/cli/format/sort.go index 7179fa0cd..8e51437e9 100644 --- a/cli/format/sort.go +++ b/cli/format/sort.go @@ -27,7 +27,7 @@ type ByEndAt []models.GettableSilence func (s ByEndAt) Len() int { return len(s) } func (s ByEndAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s ByEndAt) Less(i, j int) bool { - return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].Silence.EndsAt)) + return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].EndsAt)) } type ByStartsAt []*models.GettableAlert diff --git a/cluster/cluster_test.go b/cluster/cluster_test.go index db42aea11..1b46aeb71 100644 --- a/cluster/cluster_test.go +++ b/cluster/cluster_test.go @@ -105,7 +105,7 @@ func testJoinLeave(t *testing.T) { p2.Leave(0 * time.Second) require.Equal(t, 1, p.ClusterSize()) require.Len(t, p.failedPeers, 1) - require.Equal(t, p2.Self().Address(), p.peers[p2.Self().Address()].Node.Address()) + require.Equal(t, p2.Self().Address(), p.peers[p2.Self().Address()].Address()) require.Equal(t, p2.Name(), p.failedPeers[0].Name) } @@ -341,6 +341,6 @@ func testTLSConnection(t *testing.T) { p2.Leave(0 * time.Second) require.Equal(t, 1, p1.ClusterSize()) require.Len(t, p1.failedPeers, 1) - require.Equal(t, p2.Self().Address(), p1.peers[p2.Self().Address()].Node.Address()) + require.Equal(t, p2.Self().Address(), p1.peers[p2.Self().Address()].Address()) require.Equal(t, p2.Name(), p1.failedPeers[0].Name) } diff --git a/cluster/delegate.go b/cluster/delegate.go index 678300258..5353d54da 100644 --- a/cluster/delegate.go +++ b/cluster/delegate.go @@ -236,19 +236,19 @@ func (d *delegate) MergeRemoteState(buf []byte, _ bool) { // NotifyJoin is called if a peer joins the cluster. func (d *delegate) NotifyJoin(n *memberlist.Node) { d.logger.Debug("NotifyJoin", "node", n.Name, "addr", n.Address()) - d.Peer.peerJoin(n) + d.peerJoin(n) } // NotifyLeave is called if a peer leaves the cluster. func (d *delegate) NotifyLeave(n *memberlist.Node) { d.logger.Debug("NotifyLeave", "node", n.Name, "addr", n.Address()) - d.Peer.peerLeave(n) + d.peerLeave(n) } // NotifyUpdate is called if a cluster peer gets updated. func (d *delegate) NotifyUpdate(n *memberlist.Node) { d.logger.Debug("NotifyUpdate", "node", n.Name, "addr", n.Address()) - d.Peer.peerUpdate(n) + d.peerUpdate(n) } // NotifyAlive implements the memberlist.AliveDelegate interface. diff --git a/config/config.go b/config/config.go index 82885b233..be6c5adbf 100644 --- a/config/config.go +++ b/config/config.go @@ -97,7 +97,7 @@ func (u *URL) Copy() *URL { // MarshalYAML implements the yaml.Marshaler interface for URL. func (u URL) MarshalYAML() (interface{}, error) { if u.URL != nil { - return u.URL.String(), nil + return u.String(), nil } return nil, nil } @@ -119,7 +119,7 @@ func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error { // MarshalJSON implements the json.Marshaler interface for URL. func (u URL) MarshalJSON() ([]byte, error) { if u.URL != nil { - return json.Marshal(u.URL.String()) + return json.Marshal(u.String()) } return []byte("null"), nil } @@ -145,7 +145,7 @@ type SecretURL URL func (s SecretURL) MarshalYAML() (interface{}, error) { if s.URL != nil { if MarshalSecretValue { - return s.URL.String(), nil + return s.String(), nil } return secretToken, nil } @@ -174,7 +174,7 @@ func (s SecretURL) MarshalJSON() ([]byte, error) { return json.Marshal("") } if MarshalSecretValue { - return json.Marshal(s.URL.String()) + return json.Marshal(s.String()) } return json.Marshal(secretToken) } diff --git a/config/config_test.go b/config/config_test.go index a609b9f53..113a4777b 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -818,7 +818,7 @@ func TestUnmarshalEmptyRegexp(t *testing.T) { err := json.Unmarshal(b, &re) require.NoError(t, err) require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp) - require.Equal(t, "", re.original) + require.Empty(t, re.original) } { @@ -826,7 +826,7 @@ func TestUnmarshalEmptyRegexp(t *testing.T) { err := yaml.Unmarshal(b, &re) require.NoError(t, err) require.Equal(t, regexp.MustCompile("^(?:)$"), re.Regexp) - require.Equal(t, "", re.original) + require.Empty(t, re.original) } } @@ -837,7 +837,7 @@ func TestUnmarshalNullRegexp(t *testing.T) { var re Regexp err := json.Unmarshal(input, &re) require.NoError(t, err) - require.Equal(t, "", re.original) + require.Empty(t, re.original) } { @@ -845,7 +845,7 @@ func TestUnmarshalNullRegexp(t *testing.T) { err := yaml.Unmarshal(input, &re) // Interestingly enough, unmarshalling `null` in YAML doesn't even call UnmarshalYAML. require.NoError(t, err) require.Nil(t, re.Regexp) - require.Equal(t, "", re.original) + require.Empty(t, re.original) } } diff --git a/featurecontrol/featurecontrol.go b/featurecontrol/featurecontrol.go index 1df215acb..d6da3ac88 100644 --- a/featurecontrol/featurecontrol.go +++ b/featurecontrol/featurecontrol.go @@ -131,7 +131,7 @@ func NewFlags(logger *slog.Logger, features string) (Flagger, error) { opts = append(opts, enableAutoGOMAXPROCS()) logger.Warn("Automatically set GOMAXPROCS to match Linux container CPU quota") default: - return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature) + return nil, fmt.Errorf("unknown option '%s' for --enable-feature", feature) } } diff --git a/featurecontrol/featurecontrol_test.go b/featurecontrol/featurecontrol_test.go index 87f41cbde..bd69b276c 100644 --- a/featurecontrol/featurecontrol_test.go +++ b/featurecontrol/featurecontrol_test.go @@ -35,12 +35,12 @@ func TestFlags(t *testing.T) { { name: "with only invalid feature flags", featureFlags: "somethingsomething", - err: errors.New("Unknown option 'somethingsomething' for --enable-feature"), + err: errors.New("unknown option 'somethingsomething' for --enable-feature"), }, { name: "with both, valid and invalid feature flags", featureFlags: strings.Join([]string{FeatureReceiverNameInMetrics, "somethingbad"}, ","), - err: errors.New("Unknown option 'somethingbad' for --enable-feature"), + err: errors.New("unknown option 'somethingbad' for --enable-feature"), }, } diff --git a/matcher/compat/parse.go b/matcher/compat/parse.go index f5d40cf1e..3d6a29a26 100644 --- a/matcher/compat/parse.go +++ b/matcher/compat/parse.go @@ -138,7 +138,7 @@ func FallbackMatcherParser(l *slog.Logger) ParseMatcher { } // If the input is valid in both parsers, but produces different results, // then there is disagreement. - if nErr == nil && cErr == nil && !reflect.DeepEqual(nMatcher, cMatcher) { + if cErr == nil && !reflect.DeepEqual(nMatcher, cMatcher) { l.Warn("Matchers input has disagreement", "input", input, "origin", origin) return cMatcher, nil } @@ -179,7 +179,7 @@ func FallbackMatchersParser(l *slog.Logger) ParseMatchers { // If the input is valid in both parsers, but produces different results, // then there is disagreement. We need to compare to labels.Matchers(cMatchers) // as cMatchers is a []*labels.Matcher not labels.Matchers. - if nErr == nil && cErr == nil && !reflect.DeepEqual(nMatchers, labels.Matchers(cMatchers)) { + if cErr == nil && !reflect.DeepEqual(nMatchers, labels.Matchers(cMatchers)) { l.Warn("Matchers input has disagreement", "input", input, "origin", origin) return cMatchers, nil } diff --git a/matcher/compat/parse_test.go b/matcher/compat/parse_test.go index 803ee787a..3968f7bbf 100644 --- a/matcher/compat/parse_test.go +++ b/matcher/compat/parse_test.go @@ -62,7 +62,7 @@ func TestFallbackMatcherParser(t *testing.T) { require.EqualError(t, err, test.err) } else { require.NoError(t, err) - require.EqualValues(t, test.expected, matcher) + require.Equal(t, test.expected, matcher) } }) } @@ -118,7 +118,7 @@ func TestFallbackMatchersParser(t *testing.T) { require.EqualError(t, err, test.err) } else { require.NoError(t, err) - require.EqualValues(t, test.expected, matchers) + require.Equal(t, test.expected, matchers) } }) } diff --git a/matcher/parse/parse_test.go b/matcher/parse/parse_test.go index 9a5b6955c..548b16f35 100644 --- a/matcher/parse/parse_test.go +++ b/matcher/parse/parse_test.go @@ -228,7 +228,7 @@ func TestMatchers(t *testing.T) { require.EqualError(t, err, test.error) } else { require.NoError(t, err) - require.EqualValues(t, test.expected, matchers) + require.Equal(t, test.expected, matchers) } }) } @@ -372,7 +372,7 @@ func TestMatcher(t *testing.T) { require.EqualError(t, err, test.error) } else { require.NoError(t, err) - require.EqualValues(t, test.expected, matcher) + require.Equal(t, test.expected, matcher) } }) } diff --git a/nflog/nflog.go b/nflog/nflog.go index a6c316088..584ee9b04 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -555,13 +555,13 @@ type replaceFile struct { } func (f *replaceFile) Close() error { - if err := f.File.Sync(); err != nil { + if err := f.Sync(); err != nil { return err } if err := f.File.Close(); err != nil { return err } - return os.Rename(f.File.Name(), f.filename) + return os.Rename(f.Name(), f.filename) } // openReplace opens a new temporary file that is moved to filename on closing. diff --git a/nflog/nflog_test.go b/nflog/nflog_test.go index 72fbaa5df..f4fa94013 100644 --- a/nflog/nflog_test.go +++ b/nflog/nflog_test.go @@ -361,8 +361,8 @@ func TestQuery(t *testing.T) { entries, err := nl.Query(QGroupKey("key"), QReceiver(recv)) require.NoError(t, err, "querying nflog failed") entry := entries[0] - require.EqualValues(t, firingAlerts, entry.FiringAlerts) - require.EqualValues(t, resolvedAlerts, entry.ResolvedAlerts) + require.Equal(t, firingAlerts, entry.FiringAlerts) + require.Equal(t, resolvedAlerts, entry.ResolvedAlerts) } func TestStateDecodingError(t *testing.T) { diff --git a/notify/jira/jira.go b/notify/jira/jira.go index 1ebbaad60..546f5b92d 100644 --- a/notify/jira/jira.go +++ b/notify/jira/jira.go @@ -119,7 +119,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) return n.transitionIssue(ctx, logger, existingIssue, alerts.HasFiring()) } -func (n *Notifier) prepareIssueRequestBody(ctx context.Context, logger *slog.Logger, groupID string, tmplTextFunc templateFunc) (issue, error) { +func (n *Notifier) prepareIssueRequestBody(_ context.Context, logger *slog.Logger, groupID string, tmplTextFunc templateFunc) (issue, error) { summary, err := tmplTextFunc(n.conf.Summary) if err != nil { return issue{}, fmt.Errorf("summary template: %w", err) diff --git a/notify/jira/jira_test.go b/notify/jira/jira_test.go index 39b49dacf..3225ed026 100644 --- a/notify/jira/jira_test.go +++ b/notify/jira/jira_test.go @@ -179,7 +179,7 @@ func TestSearchExistingIssue(t *testing.T) { } else { require.NoError(t, err) } - require.EqualValues(t, tc.expectedIssue, issue) + require.Equal(t, tc.expectedIssue, issue) require.Equal(t, tc.expectedRetry, retry) }) } diff --git a/notify/notify_test.go b/notify/notify_test.go index a22d36f8f..905340254 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -547,7 +547,7 @@ func TestRetryStageNoResolved(t *testing.T) { // All alerts are resolved. sent = sent[:0] ctx = WithFiringAlerts(ctx, []uint64{}) - alerts[1].Alert.EndsAt = time.Now().Add(-time.Hour) + alerts[1].EndsAt = time.Now().Add(-time.Hour) resctx, res, err = r.Exec(ctx, promslog.NewNopLogger(), alerts...) require.NoError(t, err) @@ -592,7 +592,7 @@ func TestRetryStageSendResolved(t *testing.T) { // All alerts are resolved. sent = sent[:0] ctx = WithFiringAlerts(ctx, []uint64{}) - alerts[1].Alert.EndsAt = time.Now().Add(-time.Hour) + alerts[1].EndsAt = time.Now().Add(-time.Hour) resctx, res, err = r.Exec(ctx, promslog.NewNopLogger(), alerts...) require.NoError(t, err) @@ -915,7 +915,7 @@ func TestTimeMuteStage(t *testing.T) { if len(test.mutedBy) == 0 { // All alerts should be active. - require.Equal(t, len(test.alerts), len(active)) + require.Len(t, active, len(test.alerts)) // The group should not be marked. mutedBy, isMuted := marker.Muted("route1", "group1") require.False(t, isMuted) @@ -1033,7 +1033,7 @@ func TestTimeActiveStage(t *testing.T) { if len(test.mutedBy) == 0 { // All alerts should be active. - require.Equal(t, len(test.alerts), len(active)) + require.Len(t, active, len(test.alerts)) // The group should not be marked. mutedBy, isMuted := marker.Muted("route1", "group1") require.False(t, isMuted) diff --git a/silence/silence.go b/silence/silence.go index 7e25dc3b7..9d81e7d42 100644 --- a/silence/silence.go +++ b/silence/silence.go @@ -1029,13 +1029,13 @@ type replaceFile struct { } func (f *replaceFile) Close() error { - if err := f.File.Sync(); err != nil { + if err := f.Sync(); err != nil { return err } if err := f.File.Close(); err != nil { return err } - return os.Rename(f.File.Name(), f.filename) + return os.Rename(f.Name(), f.filename) } // openReplace opens a new temporary file that is moved to filename on closing. diff --git a/silence/silence_test.go b/silence/silence_test.go index a65b1f633..58b47e390 100644 --- a/silence/silence_test.go +++ b/silence/silence_test.go @@ -430,7 +430,7 @@ func TestSilenceSet(t *testing.T) { } versionBeforeOp := s.Version() require.NoError(t, s.Set(sil1)) - require.NotEqual(t, "", sil1.Id) + require.NotEmpty(t, sil1.Id) require.NotEqual(t, versionBeforeOp, s.Version()) want := state{ @@ -457,7 +457,7 @@ func TestSilenceSet(t *testing.T) { } versionBeforeOp = s.Version() require.NoError(t, s.Set(sil2)) - require.NotEqual(t, "", sil2.Id) + require.NotEmpty(t, sil2.Id) require.NotEqual(t, versionBeforeOp, s.Version()) want = state{ @@ -740,7 +740,7 @@ func TestSilenceNoLimits(t *testing.T) { Comment: strings.Repeat("c", 2<<9), } require.NoError(t, s.Set(sil)) - require.NotEqual(t, "", sil.Id) + require.NotEmpty(t, sil.Id) } func TestSetActiveSilence(t *testing.T) { diff --git a/store/store.go b/store/store.go index e4275aa1f..11e440c14 100644 --- a/store/store.go +++ b/store/store.go @@ -123,7 +123,7 @@ func (a *Alerts) DeleteIfNotModified(alerts types.AlertSlice) error { defer a.Unlock() for _, alert := range alerts { fp := alert.Fingerprint() - if other, ok := a.c[fp]; ok && alert.UpdatedAt == other.UpdatedAt { + if other, ok := a.c[fp]; ok && alert.UpdatedAt.Equal(other.UpdatedAt) { delete(a.c, fp) } } diff --git a/template/template_test.go b/template/template_test.go index ea8915b1a..2be22b1f7 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -35,7 +35,7 @@ func TestPairNames(t *testing.T) { } expected := []string{"name1", "name2", "name3"} - require.EqualValues(t, expected, pairs.Names()) + require.Equal(t, expected, pairs.Names()) } func TestPairValues(t *testing.T) { @@ -46,7 +46,7 @@ func TestPairValues(t *testing.T) { } expected := []string{"value1", "value2", "value3"} - require.EqualValues(t, expected, pairs.Values()) + require.Equal(t, expected, pairs.Values()) } func TestPairsString(t *testing.T) { @@ -66,8 +66,8 @@ func TestKVSortedPairs(t *testing.T) { } for i, p := range kv.SortedPairs() { - require.EqualValues(t, p.Name, expectedPairs[i].Name) - require.EqualValues(t, p.Value, expectedPairs[i].Value) + require.Equal(t, p.Name, expectedPairs[i].Name) + require.Equal(t, p.Value, expectedPairs[i].Value) } // validates alertname always comes first @@ -82,8 +82,8 @@ func TestKVSortedPairs(t *testing.T) { } for i, p := range kv.SortedPairs() { - require.EqualValues(t, p.Name, expectedPairs[i].Name) - require.EqualValues(t, p.Value, expectedPairs[i].Value) + require.Equal(t, p.Name, expectedPairs[i].Name) + require.Equal(t, p.Value, expectedPairs[i].Value) } } @@ -98,7 +98,7 @@ func TestKVRemove(t *testing.T) { kv = kv.Remove([]string{"key2", "key4"}) expected := []string{"key1", "key3"} - require.EqualValues(t, expected, kv.Names()) + require.Equal(t, expected, kv.Names()) } func TestAlertsFiring(t *testing.T) { diff --git a/test/cli/acceptance.go b/test/cli/acceptance.go index a2d00885a..1ec361b20 100644 --- a/test/cli/acceptance.go +++ b/test/cli/acceptance.go @@ -200,7 +200,7 @@ func (t *AcceptanceTest) Run() { err := t.amc.Start() if err != nil { - t.T.Fatal(err) + t.Fatal(err) } // Set the reference time right before running the test actions to avoid @@ -562,7 +562,7 @@ func (amc *AlertmanagerCluster) SetSilence(at float64, sil *TestSilence) { func (am *Alertmanager) SetSilence(at float64, sil *TestSilence) { out, err := am.addSilenceCommand(sil) if err != nil { - am.t.T.Errorf("Unable to set silence %v %v", err, string(out)) + am.t.Errorf("Unable to set silence %v %v", err, string(out)) } } @@ -585,7 +585,7 @@ func (am *Alertmanager) QuerySilence(match ...string) ([]TestSilence, error) { cmd := exec.Command(amtool, args...) out, err := cmd.CombinedOutput() if err != nil { - am.t.T.Error("Silence query command failed: ", err) + am.t.Error("Silence query command failed: ", err) } return parseSilenceQueryResponse(out) } diff --git a/test/cli/mock.go b/test/cli/mock.go index 0116110ac..b4c1cadf2 100644 --- a/test/cli/mock.go +++ b/test/cli/mock.go @@ -214,7 +214,7 @@ func equalAlerts(a, b *models.GettableAlert, opts *AcceptanceOpts) bool { if (a.EndsAt == nil) != (b.EndsAt == nil) { return false } - if !(a.EndsAt == nil) && !(b.EndsAt == nil) && !equalTime(time.Time(*a.EndsAt), time.Time(*b.EndsAt), opts) { + if (a.EndsAt != nil) && (b.EndsAt != nil) && !equalTime(time.Time(*a.EndsAt), time.Time(*b.EndsAt), opts) { return false } return true diff --git a/test/with_api_v2/acceptance.go b/test/with_api_v2/acceptance.go index de59ab858..4a1f824b7 100644 --- a/test/with_api_v2/acceptance.go +++ b/test/with_api_v2/acceptance.go @@ -169,14 +169,14 @@ func (t *AcceptanceTest) Run() { for _, am := range t.amc.ams { am.errc = errc - t.T.Cleanup(am.Terminate) - t.T.Cleanup(am.cleanup) + t.Cleanup(am.Terminate) + t.Cleanup(am.cleanup) } err := t.amc.Start() if err != nil { - t.T.Log(err) - t.T.Fail() + t.Log(err) + t.Fail() return } diff --git a/test/with_api_v2/mock.go b/test/with_api_v2/mock.go index 0ac442897..d58f37c46 100644 --- a/test/with_api_v2/mock.go +++ b/test/with_api_v2/mock.go @@ -236,7 +236,7 @@ func equalAlerts(a, b *models.GettableAlert, opts *AcceptanceOpts) bool { if (a.EndsAt == nil) != (b.EndsAt == nil) { return false } - if !(a.EndsAt == nil) && !(b.EndsAt == nil) && !equalTime(time.Time(*a.EndsAt), time.Time(*b.EndsAt), opts) { + if (a.EndsAt != nil) && (b.EndsAt != nil) && !equalTime(time.Time(*a.EndsAt), time.Time(*b.EndsAt), opts) { return false } return true diff --git a/timeinterval/timeinterval.go b/timeinterval/timeinterval.go index caf81485c..64205d56b 100644 --- a/timeinterval/timeinterval.go +++ b/timeinterval/timeinterval.go @@ -436,7 +436,7 @@ func (tz Location) MarshalText() ([]byte, error) { if tz.Location == nil { return nil, fmt.Errorf("unable to convert nil location into string") } - return []byte(tz.Location.String()), nil + return []byte(tz.String()), nil } // MarshalYAML implements the yaml.Marshaler interface for Location. diff --git a/types/types_test.go b/types/types_test.go index b40ebf7ee..2c0682e69 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package types +package types //nolint:revive import ( "reflect"