From 228580cae46888c6a80ef2dd10e7ff74007a8126 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Wed, 20 Nov 2024 20:30:39 +0100 Subject: [PATCH] chore: update golangci-lint to v1.62.0 and fix reported issues. --- .github/workflows/pull-request.yml | 8 ++--- .golangci.yml | 6 ++-- .../gluon_bench/gluon_benchmarks/sync.go | 2 +- .../imap_benchmarks/server/local.go | 2 +- .../gluon_bench/reporter/json_reporter.go | 2 +- benchmarks/imaptest/main_test.go | 16 +++++----- imap/flags_test.go | 6 ++-- internal/backend/backend.go | 2 +- internal/db_impl/sqlite3/migration_test.go | 7 ++-- internal/session/handle_examine.go | 4 +-- internal/session/handle_select.go | 4 +-- internal/session/handle_status.go | 2 +- internal/state/mailbox_search.go | 2 +- internal/state/responders.go | 4 +-- internal/state/snapshot.go | 6 ++-- internal/state/snapshot_messages.go | 22 ++++++------- internal/state/snapshot_messages_test.go | 16 +++++----- internal/state/updates.go | 12 +++---- liner/liner_test.go | 11 ++++--- rfc5322/date_time_test.go | 7 ++-- rfc5322/parser_test.go | 16 +++++----- rfc822/header_parser.go | 8 ++--- rfc822/header_test.go | 20 ++++++------ rfc822/scanner_test.go | 8 ++--- store/write_controlled_store_test.go | 12 +++---- tests/append_test.go | 2 +- tests/cache_reset_test.go | 2 +- tests/check_test.go | 2 +- tests/close_test.go | 2 +- tests/connection_test.go | 6 ++-- tests/examine_test.go | 6 ++-- tests/expunge_test.go | 32 +++++++++---------- tests/fetch_test.go | 8 ++--- tests/full_state_test.go | 16 +++++----- tests/helper_test.go | 22 ++++++------- tests/login_test.go | 2 +- tests/recovery_mailbox_test.go | 2 +- tests/search_test.go | 2 +- tests/updates_test.go | 4 +-- 39 files changed, 155 insertions(+), 158 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5b693516..b5586c55 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -14,23 +14,23 @@ jobs: - name: Get sources uses: actions/checkout@v3 - - name: Set up Go 1.21 + - name: Set up Go 1.23 uses: actions/setup-go@v3 with: - go-version: '1.21' + go-version: '1.23' - name: Run go mod tidy run: go mod tidy - name: Run golangci-lint run: | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@251ceaa228607dd3e0371694a1ab2c45d21cb744 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 golangci-lint run --timeout=500s - name: Run govulncheck uses: golang/govulncheck-action@v1 with: - go-version-input: 1.21 + go-version-input: 1.23 go-package: ./... - name: Run tests diff --git a/.golangci.yml b/.golangci.yml index a876ecc7..4f767501 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - go: 1.21 + go: 1.23 skip-files: - internal/parser/parser.go - internal/parser/extern @@ -8,13 +8,11 @@ linters: presets: - bugs - comment - enable: - - wsl disable: - godox # Annoying, we have too many TODOs at the moment :p + - musttag # We do not want to force annotating every field name. - scopelint # Deprecated, replaced by exportloopref, which is enabled by default. - errorlint # Too many false positives - issues: exclude-rules: - path: benchmarks diff --git a/benchmarks/gluon_bench/gluon_benchmarks/sync.go b/benchmarks/gluon_bench/gluon_benchmarks/sync.go index d378f49d..8221871a 100644 --- a/benchmarks/gluon_bench/gluon_benchmarks/sync.go +++ b/benchmarks/gluon_bench/gluon_benchmarks/sync.go @@ -51,7 +51,7 @@ func (s *Sync) Setup(ctx context.Context, benchmarkDir string) error { gluon.WithLogger(loggerIn, loggerOut), } - server, err := gluon.New(opts...) + server, err := gluon.New(opts...) //nolint:contextcheck if err != nil { return err } diff --git a/benchmarks/gluon_bench/imap_benchmarks/server/local.go b/benchmarks/gluon_bench/imap_benchmarks/server/local.go index 254dbd76..ea5189ec 100644 --- a/benchmarks/gluon_bench/imap_benchmarks/server/local.go +++ b/benchmarks/gluon_bench/imap_benchmarks/server/local.go @@ -45,7 +45,7 @@ func (*LocalServerBuilder) New(ctx context.Context, serverPath string, profiler opts = append(opts, gluon.WithDataDir(serverPath)) opts = append(opts, gluon.WithDatabaseDir(serverPath)) - server, err := gluon.New(opts...) + server, err := gluon.New(opts...) //nolint:contextcheck if err != nil { return nil, err } diff --git a/benchmarks/gluon_bench/reporter/json_reporter.go b/benchmarks/gluon_bench/reporter/json_reporter.go index 91dd37b4..caebd93d 100644 --- a/benchmarks/gluon_bench/reporter/json_reporter.go +++ b/benchmarks/gluon_bench/reporter/json_reporter.go @@ -16,7 +16,7 @@ func (j *JSONReporter) ProduceReport(reports []*BenchmarkReport) error { return err } - return os.WriteFile(j.outputPath, []byte(result), 0o600) + return os.WriteFile(j.outputPath, result, 0o600) } func NewJSONReporter(output string) *JSONReporter { diff --git a/benchmarks/imaptest/main_test.go b/benchmarks/imaptest/main_test.go index 294e27a2..98091e2b 100644 --- a/benchmarks/imaptest/main_test.go +++ b/benchmarks/imaptest/main_test.go @@ -19,7 +19,7 @@ import ( const ( allowParallel = false - doFullIMAPtestLog = false + doFullIMAPTestLog = false gluonLogLevel = "warn" ignoreRecentError = true ) @@ -120,14 +120,14 @@ func newScenario(c caseConfig, settingName string, s settingsConfig, port int) ( port: fmt.Sprintf("%d", port), users: c.Users, name: fmt.Sprintf("u%d_c%d_%s", c.Users, c.Clients, settingName), - timeout: time.Duration(time.Second), + timeout: time.Second, } if secs, err := strconv.Atoi(s["secs"]); err == nil { sc.timeout = time.Duration(secs) * 2 * time.Second } - // coomon arguments + // Common arguments sc.imaptestParams = []string{ "host=127.0.0.1", fmt.Sprintf("port=%d", port), @@ -202,13 +202,13 @@ func (s *scenario) runGluon() { fmt.Printf("Gluon[%s]:\n%s\nGluonEnd[%s]\n", s.name, out.String(), s.name) - assert.Error(s.t, err) + require.Error(s.t, err) assert.Equal(s.t, "signal: killed", err.Error()) } func (s *scenario) runIMAPTest() { logPath := "" - if doFullIMAPtestLog { + if doFullIMAPTestLog { logPath = s.t.TempDir() + "imaptest.log" s.imaptestParams = append(s.imaptestParams, "output="+logPath) } @@ -223,12 +223,12 @@ func (s *scenario) runIMAPTest() { fmt.Printf("IMAPTEST[%s]: %q\n%s\nIMAPTESTEND[%s]\n", s.name, s.imaptestParams, out.String(), s.name) - assert.NoError(s.t, err) + require.NoError(s.t, err) assert.False(s.t, hasIMAPLogAnError(out.Bytes(), ignoreRecentError), "Error(s) found in imaptest log.") - if doFullIMAPtestLog { + if doFullIMAPTestLog { log, err := os.ReadFile(logPath) - assert.NoError(s.t, err) + require.NoError(s.t, err) fmt.Println("LOG", s.name, "\n", string(log), "\nLOG", s.name, "END") } } diff --git a/imap/flags_test.go b/imap/flags_test.go index a1a913dc..6ada8fd9 100644 --- a/imap/flags_test.go +++ b/imap/flags_test.go @@ -49,15 +49,15 @@ func TestFlagSet_Len(t *testing.T) { } func TestFlagSet_ToSlice(t *testing.T) { - require.True(t, len(NewFlagSet().ToSlice()) == 0) + require.Empty(t, NewFlagSet().ToSlice()) fs := NewFlagSet("flag1", "flag2", "FLAG2", "flag3") - require.True(t, len(fs.ToSlice()) == 3) + require.Len(t, fs.ToSlice(), 3) // Check that we return a hard copy. fs = NewFlagSet("flag1", "flag2", "flag3") sl := fs.ToSlice() - require.Equal(t, 3, len(sl)) + require.Len(t, sl, 3) // Modify something in the returned slice. sl[0] = "flag2" diff --git a/internal/backend/backend.go b/internal/backend/backend.go index 0c05f456..eeb45a50 100644 --- a/internal/backend/backend.go +++ b/internal/backend/backend.go @@ -244,7 +244,7 @@ func (b *Backend) GetState(ctx context.Context, username string, password []byte return nil, err } - state, err := b.users[userID].newState() + state, err := b.users[userID].newState() //nolint:contextcheck if err != nil { return nil, err } diff --git a/internal/db_impl/sqlite3/migration_test.go b/internal/db_impl/sqlite3/migration_test.go index 268c28eb..bc74d6a0 100644 --- a/internal/db_impl/sqlite3/migration_test.go +++ b/internal/db_impl/sqlite3/migration_test.go @@ -3,7 +3,6 @@ package sqlite3 import ( "context" "database/sql" - "errors" "fmt" "strings" "testing" @@ -51,7 +50,7 @@ func TestMigration_VersionTooHigh(t *testing.T) { err = client.Init(context.Background(), imap.DefaultEpochUIDValidityGenerator()) require.Error(t, err) - require.True(t, errors.Is(err, db.ErrInvalidDatabaseVersion)) + require.ErrorIs(t, err, db.ErrInvalidDatabaseVersion) } func TestRunMigrations(t *testing.T) { @@ -73,7 +72,7 @@ func TestRunMigrations(t *testing.T) { runAndValidateDB(t, testDir, "foo", testData, uidGenerator) } -func TestMigration_ConnectorSettingsEmtpyOnFirstUse(t *testing.T) { +func TestMigration_ConnectorSettingsEmptyOnFirstUse(t *testing.T) { testDir := t.TempDir() client, _, err := NewClient(testDir, "foo", false, false) @@ -197,7 +196,7 @@ func runAndValidateDB(t *testing.T, testDir, user string, testData *testData, ui return result.InternalID == m.messageID }) - require.True(t, idx >= 0) + require.GreaterOrEqual(t, idx, 0) require.Equal(t, m.recent, msg[idx].Recent) require.Equal(t, m.deleted, msg[idx].Deleted) diff --git a/internal/session/handle_examine.go b/internal/session/handle_examine.go index 47ab7c15..23416c77 100644 --- a/internal/session/handle_examine.go +++ b/internal/session/handle_examine.go @@ -36,8 +36,8 @@ func (s *Session) handleExamine(ctx context.Context, tag string, cmd *command.Ex } ch <- response.Flags().WithFlags(flags) - ch <- response.Exists().WithCount(imap.SeqID(mailbox.Count())) - ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent))) + ch <- response.Exists().WithCount(imap.SeqID(uint32(mailbox.Count()))) //nolint:gosec + ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent))) //nolint:gosec ch <- response.Ok().WithItems(response.ItemPermanentFlags(permFlags)) ch <- response.Ok().WithItems(response.ItemUIDNext(uidNext)) ch <- response.Ok().WithItems(response.ItemUIDValidity(mailbox.UIDValidity())) diff --git a/internal/session/handle_select.go b/internal/session/handle_select.go index 9e8fff82..3edec11c 100644 --- a/internal/session/handle_select.go +++ b/internal/session/handle_select.go @@ -37,8 +37,8 @@ func (s *Session) handleSelect(ctx context.Context, tag string, cmd *command.Sel } ch <- response.Flags().WithFlags(flags) - ch <- response.Exists().WithCount(imap.SeqID(mailbox.Count())) - ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent))) + ch <- response.Exists().WithCount(imap.SeqID(uint32(mailbox.Count()))) //nolint:gosec + ch <- response.Recent().WithCount(uint32(mailbox.GetMessagesWithFlagCount(imap.FlagRecent))) //nolint:gosec ch <- response.Ok().WithItems(response.ItemPermanentFlags(permFlags)).WithMessage("Flags permitted") ch <- response.Ok().WithItems(response.ItemUIDNext(uidNext)).WithMessage("Predicted next UID") ch <- response.Ok().WithItems(response.ItemUIDValidity(mailbox.UIDValidity())).WithMessage("UIDs valid") diff --git a/internal/session/handle_status.go b/internal/session/handle_status.go index 3063d0f1..2e6341ae 100644 --- a/internal/session/handle_status.go +++ b/internal/session/handle_status.go @@ -48,7 +48,7 @@ func (s *Session) handleStatus(ctx context.Context, tag string, cmd *command.Sta items = append(items, response.ItemUIDValidity(mailbox.UIDValidity())) case command.StatusAttributeUnseen: - items = append(items, response.ItemUnseen(uint32(mailbox.GetMessagesWithoutFlagCount(imap.FlagSeen)))) + items = append(items, response.ItemUnseen(uint32(mailbox.GetMessagesWithoutFlagCount(imap.FlagSeen)))) //nolint:gosec } } diff --git a/internal/state/mailbox_search.go b/internal/state/mailbox_search.go index a35b5841..032c14a2 100644 --- a/internal/state/mailbox_search.go +++ b/internal/state/mailbox_search.go @@ -59,7 +59,7 @@ func (m *Mailbox) Search(ctx context.Context, keys []command.SearchKey, decoder if err := parallel.DoContext(ctx, parallelism, msgCount, func(ctx context.Context, i int) error { defer async.HandlePanic(m.state.panicHandler) - msg, ok := m.snap.messages.getWithSeqID(imap.SeqID(i + 1)) + msg, ok := m.snap.messages.getWithSeqID(imap.SeqID(uint32(i + 1))) //nolint:gosec if !ok { return nil } diff --git a/internal/state/responders.go b/internal/state/responders.go index 6d5704fd..47137c8b 100644 --- a/internal/state/responders.go +++ b/internal/state/responders.go @@ -116,7 +116,7 @@ func (u *targetedExists) handle(ctx context.Context, snap *snapshot, stateID Sta } } - res := []response.Response{response.Exists().WithCount(imap.SeqID(snap.messages.len()))} + res := []response.Response{response.Exists().WithCount(imap.SeqID(uint32(snap.messages.len())))} //nolint:gosec var dbUpdate responderDBUpdate @@ -128,7 +128,7 @@ func (u *targetedExists) handle(ctx context.Context, snap *snapshot, stateID Sta } } - res = append(res, response.Recent().WithCount(uint32(recent))) + res = append(res, response.Recent().WithCount(uint32(recent))) //nolint:gosec } return res, dbUpdate, nil diff --git a/internal/state/snapshot.go b/internal/state/snapshot.go index 8e497698..490e3c0f 100644 --- a/internal/state/snapshot.go +++ b/internal/state/snapshot.go @@ -109,7 +109,7 @@ func (snap *snapshot) getAllMessages() []snapMsgWithSeq { for i, v := range allMessages { result[i] = snapMsgWithSeq{ - Seq: imap.SeqID(i + 1), + Seq: imap.SeqID(uint32(i + 1)), //nolint: gosec snapMsg: v, } } @@ -184,7 +184,7 @@ func (snap *snapshot) firstMessageWithFlag(flag string) (snapMsgWithSeq, bool) { for i, msg := range snap.messages.msg { if msg.flags.ContainsUnchecked(flagLower) { - return snapMsgWithSeq{Seq: imap.SeqID(i + 1), snapMsg: msg}, true + return snapMsgWithSeq{Seq: imap.SeqID(uint32(i + 1)), snapMsg: msg}, true //nolint:gosec } } @@ -196,7 +196,7 @@ func (snap *snapshot) firstMessageWithoutFlag(flag string) (snapMsgWithSeq, bool for i, msg := range snap.messages.msg { if !msg.flags.ContainsUnchecked(flagLower) { - return snapMsgWithSeq{Seq: imap.SeqID(i + 1), snapMsg: msg}, true + return snapMsgWithSeq{Seq: imap.SeqID(uint32(i + 1)), snapMsg: msg}, true //nolint:gosec } } diff --git a/internal/state/snapshot_messages.go b/internal/state/snapshot_messages.go index a73dc2ec..810e3869 100644 --- a/internal/state/snapshot_messages.go +++ b/internal/state/snapshot_messages.go @@ -131,7 +131,7 @@ func (list *snapMsgList) where(fn func(seq snapMsgWithSeq) bool) []snapMsgWithSe for idx, i := range list.msg { snapWithSeq := snapMsgWithSeq{ snapMsg: i, - Seq: imap.SeqID(idx + 1), + Seq: imap.SeqID(uint32(idx + 1)), //nolint:gosec } if fn(snapWithSeq) { @@ -148,7 +148,7 @@ func (list *snapMsgList) whereCount(fn func(seq snapMsgWithSeq) bool) int { for idx, i := range list.msg { snapWithSeq := snapMsgWithSeq{ snapMsg: i, - Seq: imap.SeqID(idx + 1), + Seq: imap.SeqID(uint32(idx + 1)), //nolint:gosec } if fn(snapWithSeq) { @@ -177,13 +177,13 @@ func (list *snapMsgList) get(msgID imap.InternalMessageID) (snapMsgWithSeq, bool } return snapMsgWithSeq{ - Seq: imap.SeqID(index + 1), + Seq: imap.SeqID(uint32(index + 1)), //nolint: gosec snapMsg: list.msg[index], }, ok } func (list *snapMsgList) seq(seq imap.SeqID) (snapMsgWithSeq, bool) { - if imap.SeqID(len(list.msg)) < seq { + if imap.SeqID(uint32(len(list.msg))) < seq { //nolint:gosec return snapMsgWithSeq{}, false } @@ -195,7 +195,7 @@ func (list *snapMsgList) seq(seq imap.SeqID) (snapMsgWithSeq, bool) { func (list *snapMsgList) last() snapMsgWithSeq { return snapMsgWithSeq{ - Seq: imap.SeqID(len(list.msg)), + Seq: imap.SeqID(uint32(len(list.msg))), //nolint:gosec snapMsg: list.msg[len(list.msg)-1], } } @@ -205,7 +205,7 @@ func (list *snapMsgList) seqRange(seqLo, seqHi imap.SeqID) []snapMsgWithSeq { result := make([]snapMsgWithSeq, len(interval)) for i, v := range interval { - result[i].Seq = imap.SeqID(int(seqLo) + i) + result[i].Seq = imap.SeqID(uint32(seqLo) + uint32(i)) //nolint:gosec result[i].snapMsg = v } @@ -234,7 +234,7 @@ func (list *snapMsgList) uidRange(uidLo, uidHi imap.UID) []snapMsgWithSeq { result := make([]snapMsgWithSeq, len(interval)) for i, v := range interval { - result[i].Seq = imap.SeqID(indexLo + i + 1) + result[i].Seq = imap.SeqID(uint32(indexLo + i + 1)) //nolint:gosec result[i].snapMsg = v } @@ -248,7 +248,7 @@ func (list *snapMsgList) getWithUID(uid imap.UID) (snapMsgWithSeq, bool) { } return snapMsgWithSeq{ - Seq: imap.SeqID(index + 1), + Seq: imap.SeqID(uint32(index + 1)), //nolint:gosec snapMsg: list.msg[index], }, ok } @@ -380,10 +380,10 @@ func (list *snapMsgList) resolveUIDInterval(seqSet []command.SeqRange) ([]UIDInt // - when used in a range, the order of the indexes in irrelevant. func (list *snapMsgList) resolveSeq(number command.SeqNum) (imap.SeqID, error) { if number == command.SeqNumValueAsterisk { - return imap.SeqID(list.len()), nil + return imap.SeqID(uint32(list.len())), nil //nolint:gosec } - return imap.SeqID(number), nil + return imap.SeqID(uint32(number)), nil //nolint:gosec } // resolveUID converts a textual message UID into an integer. @@ -396,7 +396,7 @@ func (list *snapMsgList) resolveUID(number command.SeqNum) (imap.UID, error) { return list.last().UID, nil } - return imap.UID(number), nil + return imap.UID(uint32(number)), nil //nolint:gosec } func (list *snapMsgList) getMessagesInSeqRange(seqSet []command.SeqRange) ([]snapMsgWithSeq, error) { diff --git a/internal/state/snapshot_messages_test.go b/internal/state/snapshot_messages_test.go index 314b4c5f..bc09b348 100644 --- a/internal/state/snapshot_messages_test.go +++ b/internal/state/snapshot_messages_test.go @@ -96,7 +96,7 @@ func TestMessageUIDRange(t *testing.T) { // UIDRange Higher than maximum { result := msg.uidRange(imap.UID(40), imap.UID(80)) - require.Equal(t, 3, len(result)) + require.Len(t, result, 3) require.Equal(t, result[0].UID, imap.UID(40)) require.Equal(t, result[1].UID, imap.UID(50)) require.Equal(t, result[2].UID, imap.UID(60)) @@ -105,7 +105,7 @@ func TestMessageUIDRange(t *testing.T) { // UIDRange Lower than minimum { result := msg.uidRange(imap.UID(1), imap.UID(10)) - require.Equal(t, 1, len(result)) + require.Len(t, result, 1) require.Equal(t, result[0].UID, imap.UID(10)) } @@ -130,7 +130,7 @@ func TestMessageUIDRange(t *testing.T) { // UIDRange for interval that is valid, but not all values exist { result := msg.uidRange(imap.UID(25), imap.UID(42)) - require.Equal(t, 2, len(result)) + require.Len(t, result, 2) require.Equal(t, result[0].UID, imap.UID(30)) require.Equal(t, result[1].UID, imap.UID(40)) } @@ -153,8 +153,8 @@ func TestMessageRange1HigherThanMax(t *testing.T) { seqInterval, err := msg.resolveSeqInterval(seqSetInterval) require.NoError(t, err) - require.Equal(t, uidInterval, []UIDInterval{{begin: imap.UID(3), end: imap.UID(3)}}) - require.Equal(t, seqInterval, []SeqInterval{{begin: imap.SeqID(3), end: imap.SeqID(3)}}) + require.Equal(t, []UIDInterval{{begin: imap.UID(3), end: imap.UID(3)}}, uidInterval) + require.Equal(t, []SeqInterval{{begin: imap.SeqID(3), end: imap.SeqID(3)}}, seqInterval) } { @@ -199,13 +199,13 @@ func TestSnapListGetMessages(t *testing.T) { seqSetInterval := []command.SeqRange{{Begin: 1, End: command.SeqNumValueAsterisk}} seqList, err := msg.getMessagesInSeqRange(seqSetInterval) require.NoError(t, err) - require.Equal(t, 2, len(seqList)) + require.Len(t, seqList, 2) require.Equal(t, seqList[0].Seq, imap.SeqID(1)) require.Equal(t, seqList[1].Seq, imap.SeqID(2)) uidList, err := msg.getMessagesInUIDRange(seqSetInterval) require.NoError(t, err) - require.Equal(t, 2, len(uidList)) + require.Len(t, uidList, 2) require.Equal(t, uidList[0].UID, imap.UID(1)) require.Equal(t, uidList[1].UID, imap.UID(2)) } @@ -216,7 +216,7 @@ func TestSnapListGetMessages(t *testing.T) { uidList, err := msg.getMessagesInUIDRange(seqSetInterval) require.NoError(t, err) - require.Equal(t, 1, len(uidList)) + require.Len(t, uidList, 1) require.Equal(t, uidList[0].UID, imap.UID(2)) } } diff --git a/internal/state/updates.go b/internal/state/updates.go index 39725589..b007ea95 100644 --- a/internal/state/updates.go +++ b/internal/state/updates.go @@ -117,7 +117,7 @@ func (state *State) applyMessageFlagsAdded(ctx context.Context, var messagesToApply []imap.MessageID for _, msg := range curFlags { - if !check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { + if !check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { //nolint:gosec // G601. Safe, and irrelevant starting with go 1.22. messagesToApply = append(messagesToApply, msg.RemoteID) } } @@ -265,7 +265,7 @@ func (state *State) applyMessageFlagsRemoved(ctx context.Context, var messagesToApply []imap.MessageID for _, msg := range curFlags { - if check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { + if check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { //nolint:gosec // G601. Safe, and irrelevant starting with go 1.22. messagesToApply = append(messagesToApply, msg.RemoteID) } } @@ -416,7 +416,7 @@ func (state *State) applyMessageFlagsSet(ctx context.Context, setList := map[bool][]imap.MessageID{true: {}, false: {}} for _, msg := range curFlags { - if hasValue := check(&setFlags); hasValue != check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { + if hasValue := check(&setFlags); hasValue != check(&msg.FlagSet) && !ids.IsRecoveredRemoteMessageID(msg.RemoteID) { //nolint:gosec // G601. Safe, and irrelevant starting with go 1.22. setList[hasValue] = append(setList[hasValue], msg.RemoteID) } } @@ -491,7 +491,7 @@ func NewMailboxRemoteIDUpdateStateUpdate(internalID imap.InternalMailboxID, remo } } -func (u *mailboxRemoteIDUpdateStateUpdate) Apply(ctx context.Context, tx db.Transaction, s *State) error { +func (u *mailboxRemoteIDUpdateStateUpdate) Apply(_ context.Context, _ db.Transaction, s *State) error { s.snap.mboxID.RemoteID = u.remoteID return nil @@ -509,7 +509,7 @@ func NewMailboxDeletedStateUpdate(mboxID imap.InternalMailboxID) Update { return &mailboxDeletedStateUpdate{MBoxIDStateFilter: MBoxIDStateFilter{MboxID: mboxID}} } -func (u *mailboxDeletedStateUpdate) Apply(ctx context.Context, tx db.Transaction, s *State) error { +func (u *mailboxDeletedStateUpdate) Apply(_ context.Context, _ db.Transaction, s *State) error { s.markInvalid() return nil @@ -527,7 +527,7 @@ func NewUIDValidityBumpedStateUpdate() Update { return &uidValidityBumpedStateUpdate{} } -func (u *uidValidityBumpedStateUpdate) Apply(ctx context.Context, tx db.Transaction, s *State) error { +func (u *uidValidityBumpedStateUpdate) Apply(_ context.Context, _ db.Transaction, s *State) error { s.markInvalid() return nil diff --git a/liner/liner_test.go b/liner/liner_test.go index 4925f412..dfb091df 100644 --- a/liner/liner_test.go +++ b/liner/liner_test.go @@ -6,6 +6,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestLinerRead(t *testing.T) { @@ -15,10 +16,10 @@ func TestLinerRead(t *testing.T) { called := 0 line, literals, err := l.Read(func() error { called++; return nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 0, called) assert.Equal(t, "tag1 login abcde pass\r\n", string(line)) - assert.Len(t, literals, 0) + assert.Empty(t, literals) } func TestLinerReadOneLiteral(t *testing.T) { @@ -28,7 +29,7 @@ func TestLinerReadOneLiteral(t *testing.T) { called := 0 line, literals, err := l.Read(func() error { called++; return nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, called) assert.Equal(t, "tag1 login {5}\r\n00010203-0405-4607-8809-0a0b0c0d0e0f pass\r\n", string(line)) assert.Equal(t, "abcde", string(literals["00010203-0405-4607-8809-0a0b0c0d0e0f"])) @@ -42,7 +43,7 @@ func TestLinerReadTwoLiterals(t *testing.T) { called := 0 line, literals, err := l.Read(func() error { called++; return nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 2, called) assert.Equal(t, "tag1 login {5}\r\n00010203-0405-4607-8809-0a0b0c0d0e0f {4}\r\n10111213-1415-4617-9819-1a1b1c1d1e1f\r\n", string(line)) assert.Equal(t, "abcde", string(literals["00010203-0405-4607-8809-0a0b0c0d0e0f"])) @@ -57,7 +58,7 @@ func TestLinerReadMultilineLiteral(t *testing.T) { called := 0 line, literals, err := l.Read(func() error { called++; return nil }) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, 1, called) assert.Equal(t, "tag1 login {15}\r\n00010203-0405-4607-8809-0a0b0c0d0e0f pass\r\n", string(line)) assert.Equal(t, "abcde\r\nabcdefgh", string(literals["00010203-0405-4607-8809-0a0b0c0d0e0f"])) diff --git a/rfc5322/date_time_test.go b/rfc5322/date_time_test.go index ffa3a670..a3be26fd 100644 --- a/rfc5322/date_time_test.go +++ b/rfc5322/date_time_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestParseDateTime(t *testing.T) { @@ -166,7 +167,7 @@ func TestParseDateTime(t *testing.T) { t.Run(test.input, func(t *testing.T) { got, err := ParseDateTime(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.want, got.Format(time.RFC3339)) }) } @@ -199,7 +200,7 @@ func TestParseDateTimeObsolete(t *testing.T) { t.Run(test.input, func(t *testing.T) { got, err := ParseDateTime(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.want, got.Format(time.RFC3339)) }) } @@ -224,7 +225,7 @@ func TestParseDateTimeRelaxed(t *testing.T) { t.Run(test.input, func(t *testing.T) { got, err := ParseDateTime(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.want, got.Format(time.RFC3339)) }) } diff --git a/rfc5322/parser_test.go b/rfc5322/parser_test.go index c9816075..74288518 100644 --- a/rfc5322/parser_test.go +++ b/rfc5322/parser_test.go @@ -262,7 +262,7 @@ func TestParseAddress(t *testing.T) { t.Run(test.input, func(t *testing.T) { addrs, err := ParseAddress(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, test.addrs, addrs) }) } @@ -422,7 +422,7 @@ func TestParseAddressList(t *testing.T) { t.Run(test.input, func(t *testing.T) { addrs, err := ParseAddressList(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, test.addrs, addrs) }) } @@ -599,7 +599,7 @@ func TestParseGroup(t *testing.T) { t.Run(test.input, func(t *testing.T) { addrs, err := ParseAddressList(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, test.addrs, addrs) }) } @@ -728,7 +728,7 @@ func TestParseSingleAddressEncodedWord(t *testing.T) { t.Run(test.input, func(t *testing.T) { addrs, err := ParseAddressList(test.input) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, test.addrs, addrs) }) } @@ -751,7 +751,7 @@ func TestParseAddressInvalid(t *testing.T) { t.Run(test, func(t *testing.T) { _, err := ParseAddressList(test) - assert.Error(t, err) + require.Error(t, err) assert.True(t, rfcparser.IsError(err)) }) } @@ -820,7 +820,7 @@ func TestParseAddressListEmoji(t *testing.T) { } addrs, err := ParseAddressList(input) - assert.NoError(t, err) + require.NoError(t, err) assert.ElementsMatch(t, expected, addrs) } @@ -884,6 +884,6 @@ func FuzzRFC5322(f *testing.F) { func TestParse_AddressAngleAddrOnlyWithSeparator(t *testing.T) { // EOF was not properly handled after separator. addrList, err := ParseAddressList(",") - assert.NoError(t, err) - require.Equal(t, addrList[0].Address, "test@user.com") + require.NoError(t, err) + require.Equal(t, "test@user.com", addrList[0].Address) } diff --git a/rfc822/header_parser.go b/rfc822/header_parser.go index f7692471..571e8dcd 100644 --- a/rfc822/header_parser.go +++ b/rfc822/header_parser.go @@ -174,19 +174,19 @@ type parsedHeaderEntry struct { valueEnd int } -func (p parsedHeaderEntry) hasKey() bool { +func (p *parsedHeaderEntry) hasKey() bool { return p.keyStart != p.keyEnd } -func (p parsedHeaderEntry) getKey(header []byte) []byte { +func (p *parsedHeaderEntry) getKey(header []byte) []byte { return header[p.keyStart:p.keyEnd] } -func (p parsedHeaderEntry) getValue(header []byte) []byte { +func (p *parsedHeaderEntry) getValue(header []byte) []byte { return header[p.valueStart:p.valueEnd] } -func (p parsedHeaderEntry) getAll(header []byte) []byte { +func (p *parsedHeaderEntry) getAll(header []byte) []byte { return header[p.keyStart:p.valueEnd] } diff --git a/rfc822/header_test.go b/rfc822/header_test.go index 81ab66b5..3889d902 100644 --- a/rfc822/header_test.go +++ b/rfc822/header_test.go @@ -34,16 +34,16 @@ func TestHeader_Has(t *testing.T) { header, err := NewHeader([]byte(literal)) require.NoError(t, err) - assert.Equal(t, true, header.Has("To")) - assert.Equal(t, true, header.Has("to")) - assert.Equal(t, false, header.Has("Too")) - assert.Equal(t, true, header.Has("From")) - assert.Equal(t, true, header.Has("from")) - assert.Equal(t, false, header.Has("fromm")) - assert.Equal(t, true, header.Has("Subject")) - assert.Equal(t, true, header.Has("subject")) - assert.Equal(t, false, header.Has("subjectt")) - assert.Equal(t, true, header.Has("References")) + assert.True(t, header.Has("To")) + assert.True(t, header.Has("to")) + assert.False(t, header.Has("Too")) + assert.True(t, header.Has("From")) + assert.True(t, header.Has("from")) + assert.False(t, header.Has("fromm")) + assert.True(t, header.Has("Subject")) + assert.True(t, header.Has("subject")) + assert.False(t, header.Has("subjectt")) + assert.True(t, header.Has("References")) } func TestHeader_Get(t *testing.T) { diff --git a/rfc822/scanner_test.go b/rfc822/scanner_test.go index 9ce5f6ac..dfc2a09d 100644 --- a/rfc822/scanner_test.go +++ b/rfc822/scanner_test.go @@ -26,7 +26,7 @@ body2 require.NoError(t, err) parts := scanner.ScanAll() - require.Equal(t, len(parts), 2) + require.Len(t, parts, 2) assert.Equal(t, "\nbody1\n", string(parts[0].Data)) assert.Equal(t, "\nbody2\n", string(parts[1].Data)) @@ -45,7 +45,7 @@ func TestScannerMalformedLineEnding(t *testing.T) { require.NoError(t, err) parts := scanner.ScanAll() - require.Equal(t, len(parts), 2) + require.Len(t, parts, 2) assert.Equal(t, "\r\nbody1\r\n", string(parts[0].Data)) assert.Equal(t, "\r\nbody2\r\n", string(parts[1].Data)) @@ -88,7 +88,7 @@ This is the epilogue. It is also to be ignored. require.NoError(t, err) parts := scanner.ScanAll() - require.Equal(t, 2, len(parts)) + require.Len(t, parts, 2) assert.Equal(t, `Content-type: multipart/mixed; boundary="nested boundary" @@ -128,7 +128,7 @@ This part does end with a linebreak. require.NoError(t, err) parts := scanner.ScanAll() - require.Equal(t, 2, len(parts)) + require.Len(t, parts, 2) assert.Equal(t, `Content-type: text/plain; charset=us-ascii diff --git a/store/write_controlled_store_test.go b/store/write_controlled_store_test.go index 9fb17946..fa047e57 100644 --- a/store/write_controlled_store_test.go +++ b/store/write_controlled_store_test.go @@ -34,28 +34,28 @@ func TestWriteControlledStore(t *testing.T) { switch i % 3 { case 0: - require.NoError(t, st.Set(id1, bytes.NewReader([]byte("literal1")))) + require.NoError(t, st.Set(id1, bytes.NewReader([]byte("literal1")))) //nolint:testifylint id = id1 case 1: - require.NoError(t, st.Set(id2, bytes.NewReader([]byte("literal2")))) + require.NoError(t, st.Set(id2, bytes.NewReader([]byte("literal2")))) //nolint:testifylint id = id2 case 2: - require.NoError(t, st.Set(id3, bytes.NewReader([]byte("literal3")))) + require.NoError(t, st.Set(id3, bytes.NewReader([]byte("literal3")))) //nolint:testifylint id = id3 } - require.NotEmpty(t, id, imap.InternalMessageID{}) + require.NotEmpty(t, id, imap.InternalMessageID{}) //nolint:testifylint // It's not guaranteed which version of the literal will be available on disk, but it should be // match one of the following literal, err := st.Get(id) - require.NoError(t, err) + require.NoError(t, err) //nolint:testifylint isEqual := bytes.Equal([]byte("literal1"), literal) || bytes.Equal([]byte("literal2"), literal) || bytes.Equal([]byte("literal3"), literal) - require.True(t, isEqual) + require.True(t, isEqual) //nolint:testifylint }(i) } diff --git a/tests/append_test.go b/tests/append_test.go index 434c4f8c..efc9e36a 100644 --- a/tests/append_test.go +++ b/tests/append_test.go @@ -128,7 +128,7 @@ func TestAppendWhileSelected(t *testing.T) { // Mailbox should have read-write modifier mailboxStatus, err := client.Select(mailboxName, false) require.NoError(t, err) - require.Equal(t, false, mailboxStatus.ReadOnly) + require.False(t, mailboxStatus.ReadOnly) // Add new message require.NoError(t, doAppendWithClientFromFile(t, client, mailboxName, messagePath, time.Now(), goimap.SeenFlag)) // EXISTS response is assigned to Messages member diff --git a/tests/cache_reset_test.go b/tests/cache_reset_test.go index 7e9c8892..2b74fbe9 100644 --- a/tests/cache_reset_test.go +++ b/tests/cache_reset_test.go @@ -55,7 +55,7 @@ func TestSearchWhenFileDeletedFromCache(t *testing.T) { seqs, err := client.Search(searchCriteria) require.NoError(t, err) - require.Equal(t, 1, len(seqs)) + require.Len(t, seqs, 1) require.Equal(t, uint32(1), seqs[0]) }) diff --git a/tests/check_test.go b/tests/check_test.go index 135513e2..a44d8159 100644 --- a/tests/check_test.go +++ b/tests/check_test.go @@ -11,7 +11,7 @@ func TestCheck(t *testing.T) { runOneToOneTestClientWithAuth(t, defaultServerOptions(t), func(client *client.Client, _ *testSession) { mailboxStatus, err := client.Select("INBOX", false) require.NoError(t, err) - require.Equal(t, false, mailboxStatus.ReadOnly) + require.False(t, mailboxStatus.ReadOnly) require.NoError(t, client.Check()) }) } diff --git a/tests/close_test.go b/tests/close_test.go index faca053a..c0e22c70 100644 --- a/tests/close_test.go +++ b/tests/close_test.go @@ -101,7 +101,7 @@ func TestCloseWithClient(t *testing.T) { { mailboxStatus, err := client.Select(messageBoxName, false) require.NoError(t, err) - require.Equal(t, false, mailboxStatus.ReadOnly) + require.False(t, mailboxStatus.ReadOnly) } { diff --git a/tests/connection_test.go b/tests/connection_test.go index 35b8752e..75a9b5f7 100644 --- a/tests/connection_test.go +++ b/tests/connection_test.go @@ -64,16 +64,14 @@ func newTestConnection(tb testing.TB, conn net.Conn) *testConnection { func (s *testConnection) C(value string) *testConnection { n, err := s.conn.Write([]byte(value + "\r\n")) require.NoError(s.tb, err) - require.Greater(s.tb, n, 0) - + require.Positive(s.tb, n) return s } func (s *testConnection) Cb(b []byte) *testConnection { n, err := s.conn.Write(append(b, []byte("\r\n")...)) require.NoError(s.tb, err) - require.Greater(s.tb, n, 0) - + require.Positive(s.tb, n) return s } diff --git a/tests/examine_test.go b/tests/examine_test.go index f1760aba..e87f781e 100644 --- a/tests/examine_test.go +++ b/tests/examine_test.go @@ -52,7 +52,7 @@ func TestExamineClient(t *testing.T) { require.ElementsMatch(t, mailboxStatus.PermanentFlags, []string{goimap.SeenFlag, goimap.DeletedFlag, goimap.FlaggedFlag}) require.Equal(t, uint32(3), mailboxStatus.UidNext) require.Equal(t, uint32(1), mailboxStatus.UidValidity) - require.Equal(t, true, mailboxStatus.ReadOnly) + require.True(t, mailboxStatus.ReadOnly) } // Examining INBOX again DOES NOT modify the RECENT value. { @@ -65,7 +65,7 @@ func TestExamineClient(t *testing.T) { require.ElementsMatch(t, mailboxStatus.PermanentFlags, []string{goimap.SeenFlag, goimap.DeletedFlag, goimap.FlaggedFlag}) require.Equal(t, uint32(3), mailboxStatus.UidNext) require.Equal(t, uint32(1), mailboxStatus.UidValidity) - require.Equal(t, true, mailboxStatus.ReadOnly) + require.True(t, mailboxStatus.ReadOnly) } { mailboxStatus, err := client.Select("Archive", true) @@ -77,7 +77,7 @@ func TestExamineClient(t *testing.T) { require.ElementsMatch(t, mailboxStatus.PermanentFlags, []string{goimap.SeenFlag, goimap.DeletedFlag, goimap.FlaggedFlag}) require.Equal(t, uint32(2), mailboxStatus.UidNext) require.Equal(t, uint32(1), mailboxStatus.UidValidity) - require.Equal(t, true, mailboxStatus.ReadOnly) + require.True(t, mailboxStatus.ReadOnly) } { _, err := client.Select("INBOX", true) diff --git a/tests/expunge_test.go b/tests/expunge_test.go index ec511d22..8f7c5564 100644 --- a/tests/expunge_test.go +++ b/tests/expunge_test.go @@ -30,10 +30,10 @@ func TestExpungeSingle(t *testing.T) { require.NoError(t, client.Append("mbox", []string{goimap.SeenFlag}, time.Now(), strings.NewReader(buildRFC5322TestLiteral("To: 1@pm.me")))) messages := storeWithRetrievalClient(t, client, createSeqSet("1"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.SeenFlag, goimap.DeletedFlag, goimap.RecentFlag}) expungedIds := expungeClient(t, client) - require.Equal(t, 1, len(expungedIds)) + require.Len(t, expungedIds, 1) require.Equal(t, uint32(1), expungedIds[0]) }) } @@ -77,13 +77,13 @@ func TestExpungeInterval(t *testing.T) { require.NoError(t, client.Append("mbox", []string{goimap.SeenFlag}, time.Now(), strings.NewReader(buildRFC5322TestLiteral(fmt.Sprintf(`To: %d@pm.me`, i))))) } messages := storeWithRetrievalClient(t, client, createSeqSet("1,3"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 2, len(messages)) + require.Len(t, messages, 2) for _, message := range messages { require.ElementsMatch(t, message.Flags, []string{goimap.SeenFlag, goimap.DeletedFlag, goimap.RecentFlag}) } expungedIds := expungeClient(t, client) - require.Equal(t, 2, len(expungedIds)) - require.Equal(t, expungedIds, []uint32{1, 2}) + require.Len(t, expungedIds, 2) + require.Equal(t, []uint32{1, 2}, expungedIds) }) } @@ -92,17 +92,17 @@ func beforeOrAfterExpungeCheck(t *testing.T, client *client.Client, mailboxName // TestExpungeWithAppendBeforeMailboxSelect and TestExpungeWithAppendAfterMailboxSelect { messages := storeWithRetrievalClient(t, client, createSeqSet("1"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } { messages := storeWithRetrievalClient(t, client, createSeqSet("2"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.RecentFlag, goimap.DeletedFlag}) } { messages := storeWithRetrievalClient(t, client, createSeqSet("3"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } @@ -170,18 +170,18 @@ func TestExpungeUID(t *testing.T) { { messages := storeWithRetrievalClient(t, client, createSeqSet("1"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } { messages := uidFetchMessagesClient(t, client, createSeqSet("1"), []goimap.FetchItem{goimap.FetchUid, goimap.FetchFlags}) - require.Equal(t, 1, len(messages)) + require.Len(t, messages, 1) require.ElementsMatch(t, messages[0].Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } { expungedIds := uidExpungeClient(t, uidClient, createSeqSet("1")) - require.Equal(t, 1, len(expungedIds)) + require.Len(t, expungedIds, 1) require.Equal(t, uint32(1), expungedIds[0]) } @@ -198,14 +198,14 @@ func TestExpungeUID(t *testing.T) { { messages := uidStoreWithRetrievalClient(t, client, createSeqSet("2,4"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 2, len(messages)) + require.Len(t, messages, 2) for _, message := range messages { require.ElementsMatch(t, message.Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } } { expungedIds := uidExpungeClient(t, uidClient, createSeqSet("4,2")) - require.Equal(t, 2, len(expungedIds)) + require.Len(t, expungedIds, 2) require.Equal(t, []uint32{1, 2}, expungedIds) } @@ -213,7 +213,7 @@ func TestExpungeUID(t *testing.T) { mailboxStatus, err := client.Status(mailboxName, []goimap.StatusItem{goimap.StatusMessages}) require.NoError(t, err) require.Equal(t, uint32(2), mailboxStatus.Messages) - require.Equal(t, 2, len(fetchMessagesClient(t, client, createSeqSet("1,2"), []goimap.FetchItem{goimap.FetchUid}))) + require.Len(t, fetchMessagesClient(t, client, createSeqSet("1,2"), []goimap.FetchItem{goimap.FetchUid}), 2) } }) } @@ -233,14 +233,14 @@ func TestExpungeResponseSequence(t *testing.T) { { messages := storeWithRetrievalClient(t, client, createSeqSet("3,4,7,11"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) - require.Equal(t, 4, len(messages)) + require.Len(t, messages, 4) for _, message := range messages { require.ElementsMatch(t, message.Flags, []string{goimap.SeenFlag, goimap.RecentFlag, goimap.DeletedFlag}) } } { expungedIds := expungeClient(t, client) - require.Equal(t, 4, len(expungedIds)) + require.Len(t, expungedIds, 4) require.Equal(t, []uint32{3, 3, 5, 8}, expungedIds) } }) diff --git a/tests/fetch_test.go b/tests/fetch_test.go index b8d76cf2..db571d0a 100644 --- a/tests/fetch_test.go +++ b/tests/fetch_test.go @@ -293,7 +293,7 @@ func TestFetchUID(t *testing.T) { require.NoError(t, client.Expunge(nil)) messages := uidFetchMessagesClient(t, client, createSeqSet("2:5"), []goimap.FetchItem{goimap.FetchEnvelope, goimap.FetchUid}) - require.Equal(t, 3, len(messages)) + require.Len(t, messages, 3) fetchResult := newFetchCommand(t, client).withItems(goimap.FetchEnvelope, goimap.FetchUid).fetchUid("5,2:4") fetchResult.forSeqNum(2, func(builder *validatorBuilder) { @@ -400,7 +400,7 @@ func TestFetchFromDataSequences(t *testing.T) { }) } -func TestFetchFromDataUids(t *testing.T) { +func TestFetchFromDataUIDs(t *testing.T) { runOneToOneTestClientWithData(t, defaultServerOptions(t), func(client *client.Client, _ *testSession, _ string, _ imap.MailboxID) { // Remove a couple of messages require.NoError(t, client.Store(createSeqSet("20:29,50:60,90"), goimap.AddFlags, []interface{}{goimap.DeletedFlag}, nil)) @@ -561,11 +561,11 @@ func afternoonMeetingMessageDataSize() uint32 { panic(err) } - return uint32(fi.Size()) + return uint32(fi.Size()) //nolint:gosec } func afternoonMeetingMessageDataSizeWithExtraHeader() uint32 { - return afternoonMeetingMessageDataSize() + uint32(len(ids.InternalIDKey)) + uint32(len(uuid.NewString())+4) + return afternoonMeetingMessageDataSize() + uint32(len(ids.InternalIDKey)) + uint32(len(uuid.NewString())+4) //nolint:gosec } func fillAndSelectMailboxWithMultipleEntries(t *testing.T, client *client.Client) { diff --git a/tests/full_state_test.go b/tests/full_state_test.go index eb410a56..ac0a0717 100644 --- a/tests/full_state_test.go +++ b/tests/full_state_test.go @@ -163,8 +163,8 @@ func TestReceptionOnIdle(t *testing.T) { require.NoError(t, err) } - require.Equal(t, existsUpdate, uint32(3), "Not received the good amount of exists update") - require.Equal(t, recentUpdate, uint32(3), "Not received the good amount of recent update") + require.Equal(t, uint32(3), existsUpdate, "Not received the good amount of exists update") + require.Equal(t, uint32(3), recentUpdate, "Not received the good amount of recent update") { expectedFlags := []string{ goimap.RecentFlag, @@ -226,7 +226,7 @@ func TestMorningFiltering(t *testing.T) { // either Delete uidStoreWithRetrievalClient(t, client, createSeqSet(strId), goimap.AddFlags, []interface{}{goimap.DeletedFlag}) expungedIds := expungeClient(t, client) - require.Equal(t, 1, len(expungedIds)) + require.Len(t, expungedIds, 1) case 1: // or unseen @@ -248,12 +248,12 @@ func TestMorningFiltering(t *testing.T) { { mailboxStatus, err := client.Status("Archive", []goimap.StatusItem{goimap.StatusMessages}) require.NoError(t, err) - require.Equal(t, uint32(nbArchived), mailboxStatus.Messages) + require.Equal(t, uint32(nbArchived), mailboxStatus.Messages) //nolint:gosec } { mailboxStatus, err := client.Status("ReadLater", []goimap.StatusItem{goimap.StatusMessages}) require.NoError(t, err) - require.Equal(t, uint32(nbUnseen), mailboxStatus.Messages) + require.Equal(t, uint32(nbUnseen), mailboxStatus.Messages) //nolint:gosec } }) } @@ -271,7 +271,7 @@ func uidFetchAndCheckFlags(t *testing.T, client *client.Client, first int, last fetchResult := newFetchCommand(t, client).withItems(sectionStr).fetchUid(seqSet) for i := first; i <= last; i++ { - fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { + fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { //nolint:gosec for _, flag := range flags { builder.wantFlags(flag) } @@ -294,7 +294,7 @@ func uidFetchAndCheckMailHeader(t *testing.T, client *client.Client, first int, fetchResult := newFetchCommand(t, client).withItems(sectionStr).fetchUid(seqSet) for i := first; i <= last; i++ { - fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { + fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { //nolint:gosec builder.ignoreFlags() if expectAfternoon { builder.wantSection(sectionNotPeekStr, @@ -325,7 +325,7 @@ func uidFetchAndCheckMailContent(t *testing.T, client *client.Client, first int, fetchResult := newFetchCommand(t, client).withItems(sectionStr).fetchUid(seqSet) for i := first; i <= last; i++ { - fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { + fetchResult.forUid(uint32(i), func(builder *validatorBuilder) { //nolint:gosec builder.ignoreFlags() if expectAfternoon { builder.wantSection(sectionStr, diff --git a/tests/helper_test.go b/tests/helper_test.go index 334941be..0cab547e 100644 --- a/tests/helper_test.go +++ b/tests/helper_test.go @@ -90,14 +90,14 @@ func listMailboxesClient(t testing.TB, client *client.Client, reference string, go func() { done <- client.List(reference, expression, mailboxesChannel) - require.NoError(t, <-done) + require.NoError(t, <-done) //nolint:testifylint }() return iterator.Collect(iterator.Chan(mailboxesChannel)) } func checkMailboxesMatchNamesAndAttributes(t *testing.T, client *client.Client, reference string, expression string, expectedNamesAndAttributes map[string][]string) { - haveNames := []string{} + var haveNames []string for _, mbox := range listMailboxesClient(t, client, reference, expression) { haveNames = append(haveNames, mbox.Name) @@ -106,7 +106,7 @@ func checkMailboxesMatchNamesAndAttributes(t *testing.T, client *client.Client, require.ElementsMatch(t, wantAttributes, mbox.Attributes, "for mailbox %q", mbox.Name) } - wantNames := []string{} + var wantNames []string for name := range expectedNamesAndAttributes { wantNames = append(wantNames, name) } @@ -131,7 +131,7 @@ func storeWithRetrievalClient(t testing.TB, client *client.Client, seqset *goima ch := make(chan *goimap.Message) go func() { - require.NoError(t, client.Store(seqset, item, value, ch)) + require.NoError(t, client.Store(seqset, item, value, ch)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(ch)) @@ -141,7 +141,7 @@ func uidStoreWithRetrievalClient(t testing.TB, client *client.Client, seqset *go ch := make(chan *goimap.Message) go func() { - require.NoError(t, client.UidStore(seqset, item, value, ch)) + require.NoError(t, client.UidStore(seqset, item, value, ch)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(ch)) @@ -163,7 +163,7 @@ func fetchMessagesClient(t testing.TB, client *client.Client, seqset *goimap.Seq ch := make(chan *goimap.Message) go func() { - require.NoError(t, client.Fetch(seqset, items, ch)) + require.NoError(t, client.Fetch(seqset, items, ch)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(ch)) @@ -173,7 +173,7 @@ func uidFetchMessagesClient(t testing.TB, client *client.Client, seqset *goimap. ch := make(chan *goimap.Message) go func() { - require.NoError(t, client.UidFetch(seqset, items, ch)) + require.NoError(t, client.UidFetch(seqset, items, ch)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(ch)) @@ -183,7 +183,7 @@ func expungeClient(t testing.TB, client *client.Client) []uint32 { expungeCh := make(chan uint32) go func() { - require.NoError(t, client.Expunge(expungeCh)) + require.NoError(t, client.Expunge(expungeCh)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(expungeCh)) @@ -193,7 +193,7 @@ func uidExpungeClient(t testing.TB, client *uidplus.Client, sequenceSet *goimap. expungeCh := make(chan uint32) go func() { - require.NoError(t, client.UidExpunge(sequenceSet, expungeCh)) + require.NoError(t, client.UidExpunge(sequenceSet, expungeCh)) //nolint:testifylint }() return iterator.Collect(iterator.Chan(expungeCh)) @@ -307,7 +307,7 @@ type messageValidator struct { func newEmptyIMAPMessageValidator() *messageValidator { return &messageValidator{ validateSeqNum: func(t testing.TB, u uint32) { - require.Greater(t, u, uint32(0)) + require.Positive(t, u) }, validateUid: func(t testing.TB, u uint32) { require.Zero(t, u) @@ -896,7 +896,7 @@ func newEmptyBodyStructureValidator() *bodyStructureValidator { validateRFCEnvelope: nil, validateRFCBodyStructure: nil, validateLines: func(tb testing.TB, u uint32) { - require.Zero(tb, 0) + require.Zero(tb, u) }, validateExtended: func(tb testing.TB, b bool) { require.True(tb, b) diff --git a/tests/login_test.go b/tests/login_test.go index be591e46..c975d5ef 100644 --- a/tests/login_test.go +++ b/tests/login_test.go @@ -151,7 +151,7 @@ func TestLoginEvents(t *testing.T) { c.C("A001 login baduser badpass").NO("A001") failedEvent, ok := (<-s.eventCh).(events.LoginFailed) require.True(t, ok) - require.Equal(t, failedEvent.Username, "baduser") + require.Equal(t, "baduser", failedEvent.Username) c.C("A002 login user pass").OK("A002") loginEvent, ok := (<-s.eventCh).(events.Login) diff --git a/tests/recovery_mailbox_test.go b/tests/recovery_mailbox_test.go index b1ba02ac..54ca98d4 100644 --- a/tests/recovery_mailbox_test.go +++ b/tests/recovery_mailbox_test.go @@ -265,7 +265,7 @@ func TestRecoveryMailboxOnlyReportsOnFirstDedupedMessage(t *testing.T) { { reports := s.reporter.getReports() - require.Equal(t, 1, len(reports)) + require.Len(t, reports, 1) } }) } diff --git a/tests/search_test.go b/tests/search_test.go index 474f854d..344cb597 100644 --- a/tests/search_test.go +++ b/tests/search_test.go @@ -43,7 +43,7 @@ func TestSearchCharSetISO88591(t *testing.T) { c.Cf(`TAG SEARCH CHARSET ISO-8859-1 BODY {%v}`, len(b)).Continue().Cb(b).S("* SEARCH 1").OK("TAG") // Search for it with ISO-8859-1 encoding (direct). - c.Cf(`TAG SEARCH CHARSET ISO-8859-1 BODY ` + string(b)).S("* SEARCH 1").OK("TAG") + c.C(`TAG SEARCH CHARSET ISO-8859-1 BODY ` + string(b)).S("* SEARCH 1").OK("TAG") }) } diff --git a/tests/updates_test.go b/tests/updates_test.go index ea898967..91bcc3c8 100644 --- a/tests/updates_test.go +++ b/tests/updates_test.go @@ -322,7 +322,7 @@ func TestMessageCreatedWithIgnoreMissingMailbox(t *testing.T) { s.messageCreatedWithMailboxes("user", []imap.MailboxID{mailboxID, "THIS MAILBOX DOES NOT EXISTS"}, []byte("To: Test"), time.Now()) status, err := c.Select("mbox", false) require.NoError(t, err) - require.Equal(t, status.Messages, uint32(0)) + require.Equal(t, uint32(0), status.Messages) } { // Second round succeeds as we publish an update that is allowed to fail. @@ -330,7 +330,7 @@ func TestMessageCreatedWithIgnoreMissingMailbox(t *testing.T) { s.messageCreatedWithMailboxes("user", []imap.MailboxID{mailboxID, "THIS MAILBOX DOES NOT EXISTS"}, []byte("To: Test"), time.Now()) status, err := c.Select("mbox", false) require.NoError(t, err) - require.Equal(t, status.Messages, uint32(1)) + require.Equal(t, uint32(1), status.Messages) } }) }