From 59a03deebb77a2fdda49ef1fa39da5afe95555c9 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 05:00:32 -0500 Subject: [PATCH 1/5] fix(deps): replace deprecated satori/go.uuid with google/uuid --- command/server_defined_unique_entity.go | 4 ++-- datastore/sync_entity.go | 4 ++-- go.mod | 5 +++-- go.sum | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/command/server_defined_unique_entity.go b/command/server_defined_unique_entity.go index a4a4acd1..16cef5f0 100644 --- a/command/server_defined_unique_entity.go +++ b/command/server_defined_unique_entity.go @@ -7,7 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/satori/go.uuid" + "github.com/google/uuid" ) const ( @@ -28,7 +28,7 @@ func createServerDefinedUniqueEntity(name string, serverDefinedTag string, clien deleted := false folder := true version := int64(1) - idString := uuid.NewV4().String() + idString := uuid.New().String() pbEntity := &sync_pb.SyncEntity{ Ctime: &now, Mtime: &now, Deleted: &deleted, Folder: &folder, diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 3e831216..79f85775 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -17,7 +17,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/brave/go-sync/schema/protobuf/sync_pb" "github.com/rs/zerolog/log" - uuid "github.com/satori/go.uuid" + "github.com/google/uuid" "google.golang.org/protobuf/proto" ) @@ -789,7 +789,7 @@ func CreateDBSyncEntity(entity *sync_pb.SyncEntity, cacheGUID *string, clientID var originatorCacheGUID, originatorClientItemID *string if cacheGUID != nil { if *entity.Version == 0 { - id = uuid.NewV4().String() + id = uuid.New().String() } originatorCacheGUID = cacheGUID originatorClientItemID = entity.IdString diff --git a/go.mod b/go.mod index 8361619f..5847ff33 100644 --- a/go.mod +++ b/go.mod @@ -8,14 +8,13 @@ require ( github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.15.24 github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.7.59 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.39.1 - github.com/aws/smithy-go v1.22.1 github.com/brave-intl/bat-go/libs v0.0.0-20250620104757-9e2f8ff87fd8 github.com/getsentry/sentry-go v0.34.0 github.com/go-chi/chi/v5 v5.2.3 + github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.23.2 github.com/redis/go-redis/v9 v9.14.0 github.com/rs/zerolog v1.34.0 - github.com/satori/go.uuid v1.2.0 github.com/stretchr/testify v1.11.1 google.golang.org/protobuf v1.36.8 ) @@ -34,6 +33,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect + github.com/aws/smithy-go v1.22.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -52,6 +52,7 @@ require ( github.com/prometheus/procfs v0.16.1 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/xid v1.6.0 // indirect + github.com/satori/go.uuid v1.2.0 // indirect github.com/shengdoushi/base58 v1.0.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/throttled/throttled/v2 v2.13.0 // indirect diff --git a/go.sum b/go.sum index 0ebae28a..2c9c0924 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,6 @@ github.com/getsentry/sentry-go v0.34.0 h1:1FCHBVp8TfSc8L10zqSwXUZNiOSF+10qw4czja github.com/getsentry/sentry-go v0.34.0/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= -github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618= -github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE= github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -94,6 +92,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= From 909c0e3d9911d64a4d8526574e881d3fed0a67f6 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 05:41:14 -0500 Subject: [PATCH 2/5] chore(lint): goimports --- auth/auth_test.go | 3 ++- cache/cache_test.go | 3 ++- command/command.go | 3 ++- command/command_test.go | 3 ++- command/server_defined_unique_entity.go | 3 ++- command/server_defined_unique_entity_test.go | 3 ++- controller/controller.go | 7 ++++--- controller/controller_test.go | 5 +++-- datastore/datastoretest/dynamo.go | 1 + datastore/datastoretest/mock_datastore.go | 3 ++- datastore/item_count_test.go | 3 ++- datastore/sync_entity.go | 5 +++-- datastore/sync_entity_test.go | 5 +++-- middleware/auth.go | 3 ++- middleware/disabled_chain.go | 5 +++-- middleware/middleware_test.go | 3 ++- server/server.go | 11 ++++++----- server/server_test.go | 3 ++- 18 files changed, 45 insertions(+), 27 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index c753e2ef..5bc1d68e 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -7,9 +7,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + "github.com/brave/go-sync/auth" "github.com/brave/go-sync/auth/authtest" - "github.com/stretchr/testify/suite" ) type AuthTestSuite struct { diff --git a/cache/cache_test.go b/cache/cache_test.go index 3ca4deb5..5b175969 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -4,8 +4,9 @@ import ( "context" "testing" - "github.com/brave/go-sync/cache" "github.com/stretchr/testify/suite" + + "github.com/brave/go-sync/cache" ) type CacheTestSuite struct { diff --git a/command/command.go b/command/command.go index 0bdd8c06..80c9c677 100644 --- a/command/command.go +++ b/command/command.go @@ -6,10 +6,11 @@ import ( "fmt" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/rs/zerolog/log" + "github.com/brave/go-sync/cache" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/rs/zerolog/log" ) var ( diff --git a/command/command_test.go b/command/command_test.go index b1c282a9..3f6d9eb3 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -10,12 +10,13 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/suite" + "github.com/brave/go-sync/cache" "github.com/brave/go-sync/command" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/stretchr/testify/suite" ) const ( diff --git a/command/server_defined_unique_entity.go b/command/server_defined_unique_entity.go index 16cef5f0..8c81f310 100644 --- a/command/server_defined_unique_entity.go +++ b/command/server_defined_unique_entity.go @@ -5,9 +5,10 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/google/uuid" + "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/google/uuid" ) const ( diff --git a/command/server_defined_unique_entity_test.go b/command/server_defined_unique_entity_test.go index 56e06faa..b53c50f5 100644 --- a/command/server_defined_unique_entity_test.go +++ b/command/server_defined_unique_entity_test.go @@ -5,10 +5,11 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/suite" + "github.com/brave/go-sync/command" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" - "github.com/stretchr/testify/suite" ) type ServerDefinedUniqueEntityTestSuite struct { diff --git a/controller/controller.go b/controller/controller.go index 7566072c..3f4422e1 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -8,15 +8,16 @@ import ( "github.com/brave-intl/bat-go/libs/closers" "github.com/brave-intl/bat-go/libs/middleware" + "github.com/go-chi/chi/v5" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/proto" + "github.com/brave/go-sync/cache" "github.com/brave/go-sync/command" syncContext "github.com/brave/go-sync/context" "github.com/brave/go-sync/datastore" syncMiddleware "github.com/brave/go-sync/middleware" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/go-chi/chi/v5" - "github.com/rs/zerolog/log" - "google.golang.org/protobuf/proto" ) const ( diff --git a/controller/controller_test.go b/controller/controller_test.go index f4703040..1dd9dbc0 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -10,6 +10,9 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/suite" + "google.golang.org/protobuf/proto" + "github.com/brave/go-sync/auth/authtest" "github.com/brave/go-sync/cache" syncContext "github.com/brave/go-sync/context" @@ -17,8 +20,6 @@ import ( "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/stretchr/testify/suite" - "google.golang.org/protobuf/proto" ) type ControllerTestSuite struct { diff --git a/datastore/datastoretest/dynamo.go b/datastore/datastoretest/dynamo.go index 4d0cab0c..3828c505 100644 --- a/datastore/datastoretest/dynamo.go +++ b/datastore/datastoretest/dynamo.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression" "github.com/aws/aws-sdk-go-v2/service/dynamodb" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/brave/go-sync/datastore" ) diff --git a/datastore/datastoretest/mock_datastore.go b/datastore/datastoretest/mock_datastore.go index 09665d40..5cda4da5 100644 --- a/datastore/datastoretest/mock_datastore.go +++ b/datastore/datastoretest/mock_datastore.go @@ -1,8 +1,9 @@ package datastoretest import ( - "github.com/brave/go-sync/datastore" "github.com/stretchr/testify/mock" + + "github.com/brave/go-sync/datastore" ) // MockDatastore is used to mock datastorein tests diff --git a/datastore/item_count_test.go b/datastore/item_count_test.go index ccb78ac2..33b82de1 100644 --- a/datastore/item_count_test.go +++ b/datastore/item_count_test.go @@ -4,9 +4,10 @@ import ( "sort" "testing" + "github.com/stretchr/testify/suite" + "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" - "github.com/stretchr/testify/suite" ) type ItemCountTestSuite struct { diff --git a/datastore/sync_entity.go b/datastore/sync_entity.go index 79f85775..0d652cd0 100644 --- a/datastore/sync_entity.go +++ b/datastore/sync_entity.go @@ -15,10 +15,11 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression" "github.com/aws/aws-sdk-go-v2/service/dynamodb" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" - "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/rs/zerolog/log" "github.com/google/uuid" + "github.com/rs/zerolog/log" "google.golang.org/protobuf/proto" + + "github.com/brave/go-sync/schema/protobuf/sync_pb" ) const ( diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 5cc24b4c..f2f3de2f 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -8,11 +8,12 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/stretchr/testify/suite" + "google.golang.org/protobuf/proto" + "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/datastore/datastoretest" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/stretchr/testify/suite" - "google.golang.org/protobuf/proto" ) type SyncEntityTestSuite struct { diff --git a/middleware/auth.go b/middleware/auth.go index 99108b91..50a74e33 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -4,9 +4,10 @@ import ( "context" "net/http" + "github.com/rs/zerolog/log" + "github.com/brave/go-sync/auth" syncContext "github.com/brave/go-sync/context" - "github.com/rs/zerolog/log" ) // Auth verifies the token provided is valid, and sets the client id in context diff --git a/middleware/disabled_chain.go b/middleware/disabled_chain.go index 282e5382..f448e636 100644 --- a/middleware/disabled_chain.go +++ b/middleware/disabled_chain.go @@ -3,11 +3,12 @@ package middleware import ( "net/http" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/proto" + syncContext "github.com/brave/go-sync/context" "github.com/brave/go-sync/datastore" "github.com/brave/go-sync/schema/protobuf/sync_pb" - "github.com/rs/zerolog/log" - "google.golang.org/protobuf/proto" ) // DisabledChain is a middleware to check for disabled sync chains referenced in a request, diff --git a/middleware/middleware_test.go b/middleware/middleware_test.go index 277f5236..b1665203 100644 --- a/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -9,11 +9,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + "github.com/brave/go-sync/auth/authtest" syncContext "github.com/brave/go-sync/context" "github.com/brave/go-sync/datastore/datastoretest" "github.com/brave/go-sync/middleware" - "github.com/stretchr/testify/suite" ) type MiddlewareTestSuite struct { diff --git a/server/server.go b/server/server.go index 67d854e0..fda6a52b 100644 --- a/server/server.go +++ b/server/server.go @@ -16,17 +16,18 @@ import ( "github.com/brave-intl/bat-go/libs/handlers" "github.com/brave-intl/bat-go/libs/logging" batware "github.com/brave-intl/bat-go/libs/middleware" - "github.com/brave/go-sync/cache" - syncContext "github.com/brave/go-sync/context" - "github.com/brave/go-sync/controller" - "github.com/brave/go-sync/datastore" - "github.com/brave/go-sync/middleware" sentry "github.com/getsentry/sentry-go" "github.com/go-chi/chi/v5" chiware "github.com/go-chi/chi/v5/middleware" "github.com/rs/zerolog" "github.com/rs/zerolog/hlog" "github.com/rs/zerolog/log" + + "github.com/brave/go-sync/cache" + syncContext "github.com/brave/go-sync/context" + "github.com/brave/go-sync/controller" + "github.com/brave/go-sync/datastore" + "github.com/brave/go-sync/middleware" ) var ( diff --git a/server/server_test.go b/server/server_test.go index 22f4ad56..6e5b5876 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -7,9 +7,10 @@ import ( "net/http/httptest" "testing" - "github.com/brave/go-sync/server" "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" + + "github.com/brave/go-sync/server" ) var ( From 56168f18d02327c2c45be2500f837169ebbe42ed Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 05:41:43 -0500 Subject: [PATCH 3/5] chore(lint): intrange --- command/command_test.go | 2 +- command/server_defined_unique_entity_test.go | 2 +- datastore/item_count.go | 2 +- datastore/sync_entity_test.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/command/command_test.go b/command/command_test.go index 3f6d9eb3..3c441b15 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -567,7 +567,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_ReplaceParentIDTo "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) suite.Require().Equal(6, len(rsp.GetUpdates.Entries)) - for i := 0; i < len(rsp.GetUpdates.Entries); i++ { + for i := range rsp.GetUpdates.Entries { if i != len(rsp.GetUpdates.Entries)-1 { suite.Assert().Equal(rsp.GetUpdates.Entries[i].OriginatorClientItemId, entries[i].IdString) } else { diff --git a/command/server_defined_unique_entity_test.go b/command/server_defined_unique_entity_test.go index b53c50f5..d86453b6 100644 --- a/command/server_defined_unique_entity_test.go +++ b/command/server_defined_unique_entity_test.go @@ -108,7 +108,7 @@ func (suite *ServerDefinedUniqueEntityTestSuite) TestInsertServerDefinedUniqueEn // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests - for i := 0; i < len(tagItems); i++ { + for i := range tagItems { suite.Assert().NotNil(tagItems[i].Ctime) suite.Assert().NotNil(tagItems[i].Mtime) diff --git a/datastore/item_count.go b/datastore/item_count.go index 13a965e2..b24d3f24 100644 --- a/datastore/item_count.go +++ b/datastore/item_count.go @@ -113,7 +113,7 @@ func (dynamo *Dynamo) initRealCountsAndUpdateHistoryCounts(counts *ClientItemCou timeSinceLastChange := now - counts.LastPeriodChangeTime if timeSinceLastChange >= periodDurationSecs { changeCount := int(timeSinceLastChange / periodDurationSecs) - for i := 0; i < changeCount; i++ { + for range changeCount { // The records from "period 1"/the earliest period // will be purged from the count, since they will be deleted via DDB TTL counts.HistoryItemCountPeriod1 = counts.HistoryItemCountPeriod2 diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index f2f3de2f..88bf5874 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -138,7 +138,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests - for i := 0; i < len(tagItems); i++ { + for i := range tagItems { suite.Assert().NotNil(tagItems[i].Ctime) suite.Assert().NotNil(tagItems[i].Mtime) @@ -285,7 +285,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntitiesWithServerTags() { // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests - for i := 0; i < len(tagItems); i++ { + for i := range tagItems { suite.Assert().NotNil(tagItems[i].Ctime) suite.Assert().NotNil(tagItems[i].Mtime) From 406b520aa2489a372912f5aac3e3f8f92bd86b48 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 06:06:54 -0500 Subject: [PATCH 4/5] chore(lint): testifylint --- auth/auth_test.go | 8 +- cache/cache_test.go | 2 +- command/command_test.go | 136 +++++------ command/server_defined_unique_entity_test.go | 14 +- datastore/item_count_test.go | 6 +- datastore/sync_entity_test.go | 238 +++++++++---------- middleware/middleware_test.go | 4 +- server/server_test.go | 7 +- 8 files changed, 208 insertions(+), 207 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 5bc1d68e..7657d664 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -21,14 +21,14 @@ func (suite *AuthTestSuite) TestAuthenticate() { // invalid token format id, err := auth.Authenticate(base64.URLEncoding.EncodeToString([]byte("||"))) suite.Require().Error(err, "invalid token format should fail") - suite.Require().Equal("", id, "empty clientID should be returned") + suite.Require().Empty(id, "empty clientID should be returned") // invalid signature _, tokenHex, _, err := authtest.GenerateToken(time.Now().UnixMilli()) suite.Require().NoError(err, "generate token should succeed") id, err = auth.Authenticate(base64.URLEncoding.EncodeToString([]byte("12" + tokenHex))) suite.Require().Error(err, "invalid signature should fail") - suite.Require().Equal("", id) + suite.Require().Empty(id) // valid token tkn, _, expectedID, err := authtest.GenerateToken(time.Now().UnixMilli()) @@ -42,13 +42,13 @@ func (suite *AuthTestSuite) TestAuthenticate() { suite.Require().NoError(err, "generate token should succeed") id, err = auth.Authenticate(tkn) suite.Require().Error(err, "outdated token should failed") - suite.Require().Equal("", id) + suite.Require().Empty(id) tkn, _, _, err = authtest.GenerateToken(time.Now().UnixMilli() + auth.TokenMaxDuration + 100) suite.Require().NoError(err, "generate token should succeed") id, err = auth.Authenticate(tkn) suite.Require().Error(err, "outdated token should failed") - suite.Require().Equal("", id) + suite.Require().Empty(id) } func (suite *AuthTestSuite) TestAuthorize() { diff --git a/cache/cache_test.go b/cache/cache_test.go index 5b175969..e86a819e 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -22,7 +22,7 @@ func (suite *CacheTestSuite) TestSetTypeMtime() { suite.cache.SetTypeMtime(context.Background(), "id", 123, 12345678) val, err := suite.cache.Get(context.Background(), "id#123", false) suite.Require().NoError(err) - suite.Require().Equal(val, "12345678") + suite.Require().Equal("12345678", val) } func (suite *CacheTestSuite) TestIsTypeMtimeUpdated() { diff --git a/command/command_test.go b/command/command_test.go index 3c441b15..c5e8c7d3 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -129,7 +129,7 @@ func getClientToServerCommitMsg(entries []*sync_pb.SyncEntity) *sync_pb.ClientTo func getMarker(suite *CommandTestSuite, tokens []int64) []*sync_pb.DataTypeProgressMarker { types := []int32{nigoriType, bookmarkType} // hard-coded types used in tests. - suite.Assert().Equal(len(types), len(tokens)) + suite.Len(tokens, len(types)) marker := []*sync_pb.DataTypeProgressMarker{} for i, token := range tokens { tokenBytes := make([]byte, binary.MaxVarintLen64) @@ -157,20 +157,20 @@ func getClientToServerGUMsg(marker []*sync_pb.DataTypeProgressMarker, func getTokensFromNewMarker(suite *CommandTestSuite, newMarker []*sync_pb.DataTypeProgressMarker) (int64, int64) { nigoriToken, n := binary.Varint(newMarker[0].Token) - suite.Assert().Greater(n, 0) + suite.Positive(n) bookmarkToken, n := binary.Varint(newMarker[1].Token) - suite.Assert().Greater(n, 0) + suite.Positive(n) return nigoriToken, bookmarkToken } func assertCommonResponse(suite *CommandTestSuite, rsp *sync_pb.ClientToServerResponse, isCommit bool) { - suite.Assert().Equal(sync_pb.SyncEnums_SUCCESS, *rsp.ErrorCode, "errorCode should match") - suite.Assert().Equal(getClientCommand(), rsp.ClientCommand, "ClientCommand should match") - suite.Assert().Equal(command.StoreBirthday, *rsp.StoreBirthday, "Birthday should match") + suite.Equal(sync_pb.SyncEnums_SUCCESS, *rsp.ErrorCode, "errorCode should match") + suite.Equal(getClientCommand(), rsp.ClientCommand, "ClientCommand should match") + suite.Equal(command.StoreBirthday, *rsp.StoreBirthday, "Birthday should match") if isCommit { - suite.Assert().NotNil(rsp.Commit) + suite.NotNil(rsp.Commit) } else { - suite.Assert().NotNil(rsp.GetUpdates) + suite.NotNil(rsp.GetUpdates) } } @@ -187,7 +187,7 @@ func assertGetUpdatesResponse(suite *CommandTestSuite, rsp *sync_pb.GetUpdatesRe tokenPtr = &(*newMarker)[1].Token } token, n := binary.Varint(*tokenPtr) - suite.Assert().Greater(n, 0) + suite.Positive(n) if token < *entity.Mtime { binary.PutVarint(*tokenPtr, *entity.Mtime) } @@ -205,10 +205,10 @@ func assertGetUpdatesResponse(suite *CommandTestSuite, rsp *sync_pb.GetUpdatesRe suite.Require().NoError(err, "json.Marshal should succeed") s2, err := json.Marshal(PBSyncAttrs) suite.Require().NoError(err, "json.Marshal should succeed") - suite.Assert().Equal(s1, s2) + suite.Equal(s1, s2) - suite.Assert().Equal(*newMarker, rsp.NewProgressMarker) - suite.Assert().Equal(expectedChangesRemaining, *rsp.ChangesRemaining) + suite.Equal(*newMarker, rsp.NewProgressMarker) + suite.Equal(expectedChangesRemaining, *rsp.ChangesRemaining) } func (suite *CommandTestSuite) TestHandleClientToServerMessage_Basic() { @@ -225,13 +225,13 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_Basic() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) commitSuccess := sync_pb.CommitResponse_SUCCESS serverIDs := []string{} commitVersions := []int64{} for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().Equal(*entryRsp.Mtime, *entryRsp.Version) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(*entryRsp.Mtime, *entryRsp.Version) serverIDs = append(serverIDs, *entryRsp.IdString) commitVersions = append(commitVersions, *entryRsp.Version) } @@ -270,12 +270,12 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_Basic() { "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(4, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 4) serverIDs = []string{} commitVersions = []int64{} for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().Equal(*entryRsp.Mtime, *entryRsp.Version) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(*entryRsp.Mtime, *entryRsp.Version) serverIDs = append(serverIDs, *entryRsp.IdString) commitVersions = append(commitVersions, *entryRsp.Version) } @@ -316,10 +316,10 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_Basic() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) commitConflict := sync_pb.CommitResponse_CONFLICT for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitConflict, *entryRsp.ResponseType) + suite.Equal(commitConflict, *entryRsp.ResponseType) } // GetUpdates again with previous returned tokens should return 0 updates. @@ -374,7 +374,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_NewClient() { // Check dummy encryption keys only for NEW_CLIENT case. expectedEncryptionKeys := make([][]byte, 1) expectedEncryptionKeys[0] = []byte("1234") - suite.Assert().Equal(expectedEncryptionKeys, rsp.GetUpdates.EncryptionKeys) + suite.Equal(expectedEncryptionKeys, rsp.GetUpdates.EncryptionKeys) } func (suite *CommandTestSuite) TestHandleClientToServerMessage_GUBatchSize() { @@ -393,11 +393,11 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_GUBatchSize() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(4, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 4) commitSuccess := sync_pb.CommitResponse_SUCCESS for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().Equal(*entryRsp.Mtime, *entryRsp.Version) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(*entryRsp.Mtime, *entryRsp.Version) } } @@ -417,13 +417,13 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_QuotaLimit() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) commitSuccess := sync_pb.CommitResponse_SUCCESS serverIDs := []string{} commitVersions := []int64{} for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().Equal(*entryRsp.Mtime, *entryRsp.Version) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(*entryRsp.Mtime, *entryRsp.Version) serverIDs = append(serverIDs, *entryRsp.IdString) commitVersions = append(commitVersions, *entryRsp.Version) } @@ -442,13 +442,13 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_QuotaLimit() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(4, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 4) overQuota := sync_pb.CommitResponse_OVER_QUOTA expectedEntryRsp := []sync_pb.CommitResponse_ResponseType{commitSuccess, commitSuccess, overQuota, overQuota} expectedVersion := []*int64{rsp.Commit.Entryresponse[0].Mtime, rsp.Commit.Entryresponse[1].Mtime, nil, nil} for i, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(expectedEntryRsp[i], *entryRsp.ResponseType) - suite.Assert().Equal(expectedVersion[i], entryRsp.Version) + suite.Equal(expectedEntryRsp[i], *entryRsp.ResponseType) + suite.Equal(expectedVersion[i], entryRsp.Version) } // Commit 2 items again when quota is already exceed should get two OVER_QUOTA @@ -463,9 +463,9 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_QuotaLimit() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(overQuota, *entryRsp.ResponseType) + suite.Equal(overQuota, *entryRsp.ResponseType) } // Commit updates to delete two previous inserted items. @@ -480,10 +480,10 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_QuotaLimit() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().Equal(*entryRsp.Mtime, *entryRsp.Version) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(*entryRsp.Mtime, *entryRsp.Version) } // Commit 4 items should have two success and two OVER_QUOTA. @@ -500,14 +500,14 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_QuotaLimit() { command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(4, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 4) expectedVersion = []*int64{rsp.Commit.Entryresponse[0].Mtime, rsp.Commit.Entryresponse[1].Mtime, nil, nil} for i, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(expectedEntryRsp[i], *entryRsp.ResponseType) + suite.Equal(expectedEntryRsp[i], *entryRsp.ResponseType) if *entryRsp.ResponseType == commitSuccess { - suite.Assert().Equal(*expectedVersion[i], *entryRsp.Version) + suite.Equal(*expectedVersion[i], *entryRsp.Version) } else { - suite.Assert().Equal(expectedVersion[i], entryRsp.Version) + suite.Equal(expectedVersion[i], entryRsp.Version) } } @@ -522,10 +522,10 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_ReplaceParentIDTo command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(1, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 1) commitSuccess := sync_pb.CommitResponse_SUCCESS for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(commitSuccess, *entryRsp.ResponseType) } // Commit parents with its child bookmarks in one commit request. @@ -551,9 +551,9 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_ReplaceParentIDTo command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(6, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 6) for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(commitSuccess, *entryRsp.ResponseType) } // Get updates to check if child's parent ID is replaced with the server @@ -566,26 +566,26 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_ReplaceParentIDTo command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Require().Equal(6, len(rsp.GetUpdates.Entries)) + suite.Require().Len(rsp.GetUpdates.Entries, 6) for i := range rsp.GetUpdates.Entries { if i != len(rsp.GetUpdates.Entries)-1 { - suite.Assert().Equal(rsp.GetUpdates.Entries[i].OriginatorClientItemId, entries[i].IdString) + suite.Equal(rsp.GetUpdates.Entries[i].OriginatorClientItemId, entries[i].IdString) } else { - suite.Assert().Equal(rsp.GetUpdates.Entries[i].OriginatorClientItemId, child0.IdString) + suite.Equal(rsp.GetUpdates.Entries[i].OriginatorClientItemId, child0.IdString) } - suite.Assert().NotNil(rsp.GetUpdates.Entries[i].IdString) + suite.NotNil(rsp.GetUpdates.Entries[i].IdString) } - suite.Assert().Equal(rsp.GetUpdates.Entries[1].ParentIdString, rsp.GetUpdates.Entries[0].IdString) - suite.Assert().Equal(rsp.GetUpdates.Entries[3].ParentIdString, rsp.GetUpdates.Entries[0].IdString) - suite.Assert().Equal(rsp.GetUpdates.Entries[4].ParentIdString, rsp.GetUpdates.Entries[2].IdString) - suite.Assert().Equal(rsp.GetUpdates.Entries[5].ParentIdString, rsp.GetUpdates.Entries[0].IdString) + suite.Equal(rsp.GetUpdates.Entries[1].ParentIdString, rsp.GetUpdates.Entries[0].IdString) + suite.Equal(rsp.GetUpdates.Entries[3].ParentIdString, rsp.GetUpdates.Entries[0].IdString) + suite.Equal(rsp.GetUpdates.Entries[4].ParentIdString, rsp.GetUpdates.Entries[2].IdString) + suite.Equal(rsp.GetUpdates.Entries[5].ParentIdString, rsp.GetUpdates.Entries[0].IdString) } func assertTypeMtimeCacheValue(suite *CommandTestSuite, key string, mtime int64, errMsg string) { val, err := suite.cache.Get(context.Background(), key, false) suite.Require().NoError(err, "cache.Get should succeed") - suite.Assert().Equal(val, strconv.FormatInt(mtime, 10), errMsg) + suite.Equal(val, strconv.FormatInt(mtime, 10), errMsg) } func insertSyncEntitiesWithoutUpdateCache( @@ -620,12 +620,12 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ba command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(3, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 3) commitSuccess := sync_pb.CommitResponse_SUCCESS var latestBookmarkMtime int64 var latestNigoriMtime int64 for i, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(commitSuccess, *entryRsp.ResponseType) if i < 2 { latestBookmarkMtime = *entryRsp.Mtime } @@ -661,7 +661,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ba command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Assert().Equal(0, len(rsp.GetUpdates.Entries)) + suite.Empty(rsp.GetUpdates.Entries) assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), latestBookmarkMtime, "cache is not updated when short circuited") assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(nigoriType)), @@ -684,9 +684,9 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ba command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(1, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 1) entryRsp := rsp.Commit.Entryresponse[0] - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) + suite.Equal(commitSuccess, *entryRsp.ResponseType) latestBookmarkMtime = *entryRsp.Mtime assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), @@ -702,9 +702,9 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ba command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Assert().Equal(2, len(rsp.GetUpdates.Entries)) - suite.Assert().Equal(latestNigoriMtime, *rsp.GetUpdates.Entries[0].Mtime) - suite.Assert().Equal(latestBookmarkMtime, *rsp.GetUpdates.Entries[1].Mtime) + suite.Len(rsp.GetUpdates.Entries, 2) + suite.Equal(latestNigoriMtime, *rsp.GetUpdates.Entries[0].Mtime) + suite.Equal(latestBookmarkMtime, *rsp.GetUpdates.Entries[1].Mtime) assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), latestBookmarkMtime, "Cached token should be equal to latest mtime") assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(nigoriType)), @@ -723,9 +723,9 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Sk command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(1, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 1) commitSuccess := sync_pb.CommitResponse_SUCCESS - suite.Assert().Equal(commitSuccess, *rsp.Commit.Entryresponse[0].ResponseType) + suite.Equal(commitSuccess, *rsp.Commit.Entryresponse[0].ResponseType) latestBookmarkMtime := *rsp.Commit.Entryresponse[0].Mtime assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), latestBookmarkMtime, @@ -750,7 +750,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Sk command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Require().Equal(1, len(rsp.GetUpdates.Entries)) + suite.Require().Len(rsp.GetUpdates.Entries, 1) suite.Require().Equal(dbEntries[0].Mtime, rsp.GetUpdates.Entries[0].Mtime) assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), *dbEntries[0].Mtime, "Successful commit should update the cache") @@ -769,12 +769,12 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ch command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, true) - suite.Assert().Equal(2, len(rsp.Commit.Entryresponse)) + suite.Len(rsp.Commit.Entryresponse, 2) commitSuccess := sync_pb.CommitResponse_SUCCESS var latestBookmarkMtime int64 for _, entryRsp := range rsp.Commit.Entryresponse { - suite.Assert().Equal(commitSuccess, *entryRsp.ResponseType) - suite.Assert().NotEqual(latestBookmarkMtime, *entryRsp.Mtime) + suite.Equal(commitSuccess, *entryRsp.ResponseType) + suite.NotEqual(latestBookmarkMtime, *entryRsp.Mtime) latestBookmarkMtime = *entryRsp.Mtime } assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), @@ -792,7 +792,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ch command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Require().Equal(2, len(rsp.GetUpdates.Entries)) + suite.Require().Len(rsp.GetUpdates.Entries, 2) suite.Require().Equal(int64(0), *rsp.GetUpdates.ChangesRemaining) mtime := *rsp.GetUpdates.Entries[0].Mtime assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), @@ -809,7 +809,7 @@ func (suite *CommandTestSuite) TestHandleClientToServerMessage_TypeMtimeCache_Ch command.HandleClientToServerMessage(suite.cache, msg, rsp, suite.dynamo, clientID), "HandleClientToServerMessage should succeed") assertCommonResponse(suite, rsp, false) - suite.Require().Equal(1, len(rsp.GetUpdates.Entries)) + suite.Require().Len(rsp.GetUpdates.Entries, 1) suite.Require().Equal(int64(0), *rsp.GetUpdates.ChangesRemaining) assertTypeMtimeCacheValue(suite, clientID+"#"+strconv.Itoa(int(bookmarkType)), latestBookmarkMtime, diff --git a/command/server_defined_unique_entity_test.go b/command/server_defined_unique_entity_test.go index d86453b6..320c0ed5 100644 --- a/command/server_defined_unique_entity_test.go +++ b/command/server_defined_unique_entity_test.go @@ -109,8 +109,8 @@ func (suite *ServerDefinedUniqueEntityTestSuite) TestInsertServerDefinedUniqueEn // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests for i := range tagItems { - suite.Assert().NotNil(tagItems[i].Ctime) - suite.Assert().NotNil(tagItems[i].Mtime) + suite.NotNil(tagItems[i].Ctime) + suite.NotNil(tagItems[i].Mtime) tagItems[i].Ctime = nil tagItems[i].Mtime = nil @@ -118,7 +118,7 @@ func (suite *ServerDefinedUniqueEntityTestSuite) TestInsertServerDefinedUniqueEn sort.Sort(datastore.TagItemByClientIDID(tagItems)) sort.Sort(datastore.TagItemByClientIDID(expectedTagItems)) - suite.Assert().Equal(tagItems, expectedTagItems) + suite.Equal(expectedTagItems, tagItems) syncItems, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") @@ -134,7 +134,7 @@ func (suite *ServerDefinedUniqueEntityTestSuite) TestInsertServerDefinedUniqueEn break } } - suite.Assert().NotEqual(bookmarksRootID, "", "Cannot find ID of bookmarks root folder") + suite.NotEmpty(bookmarksRootID, "Cannot find ID of bookmarks root folder") // For each item returned by ScanSyncEntities, make sure it is in the map and // its value is matched, then remove it from the map. @@ -149,11 +149,11 @@ func (suite *ServerDefinedUniqueEntityTestSuite) TestInsertServerDefinedUniqueEn Folder: item.Folder, } - suite.Assert().NotNil(item.ServerDefinedUniqueTag) - suite.Assert().Equal(syncAttrs, *expectedSyncAttrsMap[*item.ServerDefinedUniqueTag]) + suite.NotNil(item.ServerDefinedUniqueTag) + suite.Equal(syncAttrs, *expectedSyncAttrsMap[*item.ServerDefinedUniqueTag]) delete(expectedSyncAttrsMap, *item.ServerDefinedUniqueTag) } - suite.Assert().Equal(0, len(expectedSyncAttrsMap)) + suite.Empty(expectedSyncAttrsMap) suite.Require().NoError( command.InsertServerDefinedUniqueEntities(suite.dynamo, "client2"), diff --git a/datastore/item_count_test.go b/datastore/item_count_test.go index 33b82de1..9260b030 100644 --- a/datastore/item_count_test.go +++ b/datastore/item_count_test.go @@ -47,13 +47,13 @@ func (suite *ItemCountTestSuite) TestGetClientItemCount() { for _, item := range items { count, err := suite.dynamo.GetClientItemCount(item.ClientID) suite.Require().NoError(err, "GetClientItemCount should succeed") - suite.Assert().Equal(count.ItemCount, item.ItemCount, "ItemCount should match") + suite.Equal(count.ItemCount, item.ItemCount, "ItemCount should match") } // Non-exist client item count should succeed with count = 0. count, err := suite.dynamo.GetClientItemCount("client3") suite.Require().NoError(err, "Get non-exist ClientItemCount should succeed") - suite.Assert().Equal(count.ItemCount, 0) + suite.Equal(0, count.ItemCount) } func (suite *ItemCountTestSuite) TestUpdateClientItemCount() { @@ -82,7 +82,7 @@ func (suite *ItemCountTestSuite) TestUpdateClientItemCount() { clientCountItems[i].Version = 0 clientCountItems[i].LastPeriodChangeTime = 0 } - suite.Assert().Equal(expectedItems, clientCountItems) + suite.Equal(expectedItems, clientCountItems) } func TestItemCountTestSuite(t *testing.T) { diff --git a/datastore/sync_entity_test.go b/datastore/sync_entity_test.go index 88bf5874..128fd268 100644 --- a/datastore/sync_entity_test.go +++ b/datastore/sync_entity_test.go @@ -52,18 +52,18 @@ func (suite *SyncEntityTestSuite) TestNewServerClientUniqueTagItem() { // We can't know the exact value for Mtime & Ctime. Make sure they're set, // set zero value for subsequent tests - suite.Assert().NotNil(actualClientTag.Mtime) - suite.Assert().NotNil(actualClientTag.Ctime) - suite.Assert().NotNil(actualServerTag.Mtime) - suite.Assert().NotNil(actualServerTag.Ctime) + suite.NotNil(actualClientTag.Mtime) + suite.NotNil(actualClientTag.Ctime) + suite.NotNil(actualServerTag.Mtime) + suite.NotNil(actualServerTag.Ctime) actualClientTag.Mtime = nil actualClientTag.Ctime = nil actualServerTag.Mtime = nil actualServerTag.Ctime = nil - suite.Assert().Equal(expectedServerTag, actualServerTag) - suite.Assert().Equal(expectedClientTag, actualClientTag) + suite.Equal(expectedServerTag, actualServerTag) + suite.Equal(expectedClientTag, actualClientTag) } func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { @@ -90,11 +90,11 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { // Each InsertSyncEntity without client tag should result in one sync item saved. tagItems, err := datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal( - 0, len(tagItems), "Insert without client tag should not insert tag items") + suite.Empty( + tagItems, "Insert without client tag should not insert tag items") syncItems, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity1, entity2}) + suite.Equal([]datastore.SyncEntity{entity1, entity2}, syncItems) // Insert entity with client tag should result in one sync item and one tag // item saved. @@ -116,7 +116,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { entity4Copy.ID = "id4_copy" conflict, err := suite.dynamo.InsertSyncEntity(&entity4Copy) suite.Require().Error(err, "InsertSyncEntity with the same client tag and ClientID should fail") - suite.Assert().True(conflict, "Return conflict for duplicate client tag") + suite.True(conflict, "Return conflict for duplicate client tag") // Insert entity with the same client tag for other client should not fail. entity5 := entity3 @@ -131,7 +131,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { suite.Require().NoError(err, "ScanSyncEntities should succeed") expectedSyncItems := []datastore.SyncEntity{entity1, entity2, entity3, entity4, entity5} sort.Sort(datastore.SyncEntityByClientIDID(syncItems)) - suite.Assert().Equal(syncItems, expectedSyncItems) + suite.Equal(expectedSyncItems, syncItems) // Check tag items should be saved for entity3, entity4, entity5. tagItems, err = datastoretest.ScanTagItems(suite.dynamo) @@ -139,8 +139,8 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests for i := range tagItems { - suite.Assert().NotNil(tagItems[i].Ctime) - suite.Assert().NotNil(tagItems[i].Mtime) + suite.NotNil(tagItems[i].Ctime) + suite.NotNil(tagItems[i].Mtime) tagItems[i].Ctime = nil tagItems[i].Mtime = nil @@ -153,7 +153,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntity() { {ClientID: "client2", ID: "Client#tag1"}, } sort.Sort(datastore.TagItemByClientIDID(tagItems)) - suite.Assert().Equal(expectedTagItems, tagItems) + suite.Equal(expectedTagItems, tagItems) } func (suite *SyncEntityTestSuite) TestHasServerDefinedUniqueTag() { @@ -181,19 +181,19 @@ func (suite *SyncEntityTestSuite) TestHasServerDefinedUniqueTag() { hasTag, err := suite.dynamo.HasServerDefinedUniqueTag("client1", "tag1") suite.Require().NoError(err, "HasServerDefinedUniqueTag should succeed") - suite.Assert().Equal(hasTag, true) + suite.True(hasTag) hasTag, err = suite.dynamo.HasServerDefinedUniqueTag("client1", "tag2") suite.Require().NoError(err, "HasServerDefinedUniqueTag should succeed") - suite.Assert().Equal(hasTag, false) + suite.False(hasTag) hasTag, err = suite.dynamo.HasServerDefinedUniqueTag("client2", "tag1") suite.Require().NoError(err, "HasServerDefinedUniqueTag should succeed") - suite.Assert().Equal(hasTag, false) + suite.False(hasTag) hasTag, err = suite.dynamo.HasServerDefinedUniqueTag("client2", "tag2") suite.Require().NoError(err, "HasServerDefinedUniqueTag should succeed") - suite.Assert().Equal(hasTag, true) + suite.True(hasTag) } func (suite *SyncEntityTestSuite) TestHasItem() { @@ -221,19 +221,19 @@ func (suite *SyncEntityTestSuite) TestHasItem() { hasTag, err := suite.dynamo.HasItem("client1", "id1") suite.Require().NoError(err, "HasItem should succeed") - suite.Assert().Equal(hasTag, true) + suite.True(hasTag) hasTag, err = suite.dynamo.HasItem("client2", "id2") suite.Require().NoError(err, "HasItem should succeed") - suite.Assert().Equal(hasTag, true) + suite.True(hasTag) hasTag, err = suite.dynamo.HasItem("client2", "id3") suite.Require().NoError(err, "HasItem should succeed") - suite.Assert().Equal(hasTag, false) + suite.False(hasTag) hasTag, err = suite.dynamo.HasItem("client3", "id2") suite.Require().NoError(err, "HasItem should succeed") - suite.Assert().Equal(hasTag, false) + suite.False(hasTag) } func (suite *SyncEntityTestSuite) TestInsertSyncEntitiesWithServerTags() { @@ -260,10 +260,10 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntitiesWithServerTags() { // Check nothing is written to DB when it fails. syncItems, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(0, len(syncItems), "No items should be written if fail") + suite.Empty(syncItems, "No items should be written if fail") tagItems, err := datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(0, len(tagItems), "No items should be written if fail") + suite.Empty(tagItems, "No items should be written if fail") entity2.ServerDefinedUniqueTag = aws.String("tag2") entity3 := entity1 @@ -279,15 +279,15 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntitiesWithServerTags() { suite.Require().NoError(err, "ScanSyncEntities should succeed") expectedSyncItems := []datastore.SyncEntity{entity1, entity2, entity3} sort.Sort(datastore.SyncEntityByClientIDID(syncItems)) - suite.Assert().Equal(syncItems, expectedSyncItems) + suite.Equal(expectedSyncItems, syncItems) tagItems, err = datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") // Check that Ctime and Mtime have been set, reset to zero value for subsequent // tests for i := range tagItems { - suite.Assert().NotNil(tagItems[i].Ctime) - suite.Assert().NotNil(tagItems[i].Mtime) + suite.NotNil(tagItems[i].Ctime) + suite.NotNil(tagItems[i].Mtime) tagItems[i].Ctime = nil tagItems[i].Mtime = nil @@ -299,7 +299,7 @@ func (suite *SyncEntityTestSuite) TestInsertSyncEntitiesWithServerTags() { {ClientID: "client2", ID: "Server#tag1"}, } sort.Sort(datastore.TagItemByClientIDID(tagItems)) - suite.Assert().Equal(expectedTagItems, tagItems) + suite.Equal(expectedTagItems, tagItems) } func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { @@ -329,7 +329,7 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { // Check sync entities are inserted correctly in DB. syncItems, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity1, entity2, entity3}) + suite.Equal([]datastore.SyncEntity{entity1, entity2, entity3}, syncItems) // Update without optional fields. updateEntity1 := entity1 @@ -341,8 +341,8 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { updateEntity1.Specifics = []byte{3, 4} conflict, deleted, err := suite.dynamo.UpdateSyncEntity(&updateEntity1, *entity1.Version) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().True(deleted, "Delete operation should return true") + suite.False(conflict, "Successful update should not have conflict") + suite.True(deleted, "Delete operation should return true") // Update with optional fields. updateEntity2 := updateEntity1 @@ -355,8 +355,8 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { updateEntity2.NonUniqueName = aws.String("non_unique_name") conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity2, *entity2.Version) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().False(deleted, "Non-delete operation should return false") + suite.False(conflict, "Successful update should not have conflict") + suite.False(deleted, "Non-delete operation should return false") // Update with nil Folder and Deleted updateEntity3 := updateEntity1 @@ -365,8 +365,8 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { updateEntity3.Deleted = nil conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity3, *entity3.Version) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().False(deleted, "Non-delete operation should return false") + suite.False(conflict, "Successful update should not have conflict") + suite.False(deleted, "Non-delete operation should return false") // Reset these back to false because they will be the expected value in DB. updateEntity3.Folder = aws.Bool(false) updateEntity3.Deleted = aws.Bool(false) @@ -375,13 +375,13 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_Basic() { // should return false. conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity2, 12345678) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().True(conflict, "Update with the same version should return conflict") - suite.Assert().False(deleted, "Conflict operation should return false for delete") + suite.True(conflict, "Update with the same version should return conflict") + suite.False(deleted, "Conflict operation should return false for delete") // Check sync entities are updated correctly in DB. syncItems, err = datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{updateEntity1, updateEntity2, updateEntity3}) + suite.Equal([]datastore.SyncEntity{updateEntity1, updateEntity2, updateEntity3}, syncItems) } func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_HistoryType() { @@ -401,7 +401,7 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_HistoryType() { } conflict, err := suite.dynamo.InsertSyncEntity(&entity1) suite.Require().NoError(err, "InsertSyncEntity should succeed") - suite.Assert().False(conflict, "Successful insert should not have conflict") + suite.False(conflict, "Successful insert should not have conflict") updateEntity1 := entity1 updateEntity1.Version = aws.Int64(2) @@ -409,8 +409,8 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_HistoryType() { updateEntity1.Mtime = aws.Int64(24242424) conflict, deleted, err := suite.dynamo.UpdateSyncEntity(&updateEntity1, 1) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().False(deleted, "Non-delete operation should return false") + suite.False(conflict, "Successful update should not have conflict") + suite.False(deleted, "Non-delete operation should return false") // should still succeed with the same version number, // since the version number should be ignored @@ -418,20 +418,20 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_HistoryType() { updateEntity2.Mtime = aws.Int64(42424242) conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity2, 1) suite.Require().NoError(err, "UpdateSyncEntity should not return an error") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().False(deleted, "Non-delete operation should return false") + suite.False(conflict, "Successful update should not have conflict") + suite.False(deleted, "Non-delete operation should return false") updateEntity3 := entity1 updateEntity3.Deleted = aws.Bool(true) conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity3, 1) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().True(deleted, "Delete operation should return true") + suite.False(conflict, "Successful update should not have conflict") + suite.True(deleted, "Delete operation should return true") syncItems, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{updateEntity3}) + suite.Equal([]datastore.SyncEntity{updateEntity3}, syncItems) } func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_ReuseClientTag() { @@ -451,12 +451,12 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_ReuseClientTag() { } conflict, err := suite.dynamo.InsertSyncEntity(&entity1) suite.Require().NoError(err, "InsertSyncEntity should succeed") - suite.Assert().False(conflict, "Successful insert should not have conflict") + suite.False(conflict, "Successful insert should not have conflict") // Check a tag item is inserted. tagItems, err := datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(1, len(tagItems), "Tag item should be inserted") + suite.Len(tagItems, 1, "Tag item should be inserted") // Update it to version 23456789. updateEntity1 := entity1 @@ -467,39 +467,39 @@ func (suite *SyncEntityTestSuite) TestUpdateSyncEntity_ReuseClientTag() { updateEntity1.Specifics = []byte{3, 4} conflict, deleted, err := suite.dynamo.UpdateSyncEntity(&updateEntity1, *entity1.Version) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().False(deleted, "Non-delete operation should return false") + suite.False(conflict, "Successful update should not have conflict") + suite.False(deleted, "Non-delete operation should return false") // Soft-delete the item with wrong version should get conflict. updateEntity1.Deleted = aws.Bool(true) conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity1, *entity1.Version) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().True(conflict, "Version mismatched update should have conflict") - suite.Assert().False(deleted, "Failed delete operation should return false") + suite.True(conflict, "Version mismatched update should have conflict") + suite.False(deleted, "Failed delete operation should return false") // Soft-delete the item with matched version. updateEntity1.Version = aws.Int64(34567890) conflict, deleted, err = suite.dynamo.UpdateSyncEntity(&updateEntity1, 23456789) suite.Require().NoError(err, "UpdateSyncEntity should succeed") - suite.Assert().False(conflict, "Successful update should not have conflict") - suite.Assert().True(deleted, "Delete operation should return true") + suite.False(conflict, "Successful update should not have conflict") + suite.True(deleted, "Delete operation should return true") // Check tag item is deleted. tagItems, err = datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(0, len(tagItems), "Tag item should be deleted") + suite.Empty(tagItems, "Tag item should be deleted") // Insert another item with the same client tag again. entity2 := entity1 entity2.ID = "id2" conflict, err = suite.dynamo.InsertSyncEntity(&entity2) suite.Require().NoError(err, "InsertSyncEntity should succeed") - suite.Assert().False(conflict, "Successful insert should not have conflict") + suite.False(conflict, "Successful insert should not have conflict") // Check a tag item is inserted. tagItems, err = datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(1, len(tagItems), "Tag item should be inserted") + suite.Len(tagItems, 1, "Tag item should be inserted") } func (suite *SyncEntityTestSuite) TestGetUpdatesForType() { @@ -554,52 +554,52 @@ func (suite *SyncEntityTestSuite) TestGetUpdatesForType() { // Get all updates for type 123 and client1 using token = 0. hasChangesRemaining, syncItems, err := suite.dynamo.GetUpdatesForType(123, 0, true, "client1", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity1, entity2}) - suite.Assert().False(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity1, entity2}, syncItems) + suite.False(hasChangesRemaining) // Get all updates for type 124 and client1 using token = 0. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(124, 0, true, "client1", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity3}) - suite.Assert().False(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity3}, syncItems) + suite.False(hasChangesRemaining) // Get all updates for type 123 and client2 using token = 0. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, true, "client2", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity4}) - suite.Assert().False(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity4}, syncItems) + suite.False(hasChangesRemaining) // Get all updates for type 124 and client2 using token = 0. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(124, 0, true, "client2", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(len(syncItems), 0) - suite.Assert().False(hasChangesRemaining) + suite.Empty(syncItems) + suite.False(hasChangesRemaining) // Test maxSize will limit the return entries size, and hasChangesRemaining // should be true when there are more updates available in the DB. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, true, "client1", 1) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity1}) - suite.Assert().True(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity1}, syncItems) + suite.True(hasChangesRemaining) // Test when num of query items equal to the limit, hasChangesRemaining should // be true. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, true, "client1", 2) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity1, entity2}) - suite.Assert().True(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity1, entity2}, syncItems) + suite.True(hasChangesRemaining) // Test fetchFolders will remove folder items if false hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, false, "client1", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity2}) - suite.Assert().False(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity2}, syncItems) + suite.False(hasChangesRemaining) // Get all updates for a type for a client using mtime of one item as token. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 12345678, true, "client1", 100) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, []datastore.SyncEntity{entity2}) - suite.Assert().False(hasChangesRemaining) + suite.Equal([]datastore.SyncEntity{entity2}, syncItems) + suite.False(hasChangesRemaining) // Test batch is working correctly for over 100 items err = datastoretest.ResetTable(suite.dynamo) @@ -632,15 +632,15 @@ func (suite *SyncEntityTestSuite) TestGetUpdatesForType() { hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, true, "client1", 300) suite.Require().NoError(err, "GetUpdatesForType should succeed") sort.Sort(datastore.SyncEntityByMtime(expectedSyncItems)) - suite.Assert().Equal(syncItems, expectedSyncItems) - suite.Assert().False(hasChangesRemaining) + suite.Equal(expectedSyncItems, syncItems) + suite.False(hasChangesRemaining) // Test that when maxGUBatchSize is smaller than total updates, the first n // items ordered by Mtime should be returned. hasChangesRemaining, syncItems, err = suite.dynamo.GetUpdatesForType(123, 0, true, "client1", 200) suite.Require().NoError(err, "GetUpdatesForType should succeed") - suite.Assert().Equal(syncItems, expectedSyncItems[0:200]) - suite.Assert().True(hasChangesRemaining) + suite.Equal(syncItems, expectedSyncItems[0:200]) + suite.True(hasChangesRemaining) } func (suite *SyncEntityTestSuite) TestCreateDBSyncEntity() { @@ -692,67 +692,67 @@ func (suite *SyncEntityTestSuite) TestCreateDBSyncEntity() { suite.Require().NoError(err, "CreateDBSyncEntity should succeed") // Check ID is replaced with a server-generated ID. - suite.Assert().NotEqual( + suite.NotEqual( dbEntity.ID, *pbEntity.IdString, "ID should be a server-generated ID and not equal to the passed IdString") expectedDBEntity.ID = dbEntity.ID // Check Mtime and Ctime should be provided by the server if client does not // provide it. - suite.Assert().NotNil( + suite.NotNil( dbEntity.Ctime, "Mtime should not be nil if client did not pass one") - suite.Assert().NotNil( + suite.NotNil( dbEntity.Mtime, "Mtime should not be nil if client did not pass one") - suite.Assert().Equal( + suite.Equal( *dbEntity.Mtime, *dbEntity.Ctime, "Server should generate the same value for mtime and ctime when they're not provided by the client") expectedDBEntity.Ctime = dbEntity.Ctime expectedDBEntity.Mtime = dbEntity.Mtime expectedDBEntity.DataTypeMtime = aws.String("47745#" + strconv.FormatInt(*dbEntity.Mtime, 10)) - suite.Assert().Equal(dbEntity, &expectedDBEntity) - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.Equal(&expectedDBEntity, dbEntity) + suite.Nil(dbEntity.ExpirationTime) pbEntity.Deleted = nil pbEntity.Folder = nil dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") suite.Require().NoError(err, "CreateDBSyncEntity should succeed") - suite.Assert().False(*dbEntity.Deleted, "Default value should be set for Deleted for new entities") - suite.Assert().False(*dbEntity.Folder, "Default value should be set for Deleted for new entities") - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.False(*dbEntity.Deleted, "Default value should be set for Deleted for new entities") + suite.False(*dbEntity.Folder, "Default value should be set for Deleted for new entities") + suite.Nil(dbEntity.ExpirationTime) // Check the case when Ctime and Mtime are provided by the client. pbEntity.Ctime = aws.Int64(12345678) pbEntity.Mtime = aws.Int64(12345678) dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") suite.Require().NoError(err, "CreateDBSyncEntity should succeed") - suite.Assert().Equal(*dbEntity.Ctime, *pbEntity.Ctime, "Client's Ctime should be respected") - suite.Assert().NotEqual(*dbEntity.Mtime, *pbEntity.Mtime, "Client's Mtime should be replaced") - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.Equal(*dbEntity.Ctime, *pbEntity.Ctime, "Client's Ctime should be respected") + suite.NotEqual(*dbEntity.Mtime, *pbEntity.Mtime, "Client's Mtime should be replaced") + suite.Nil(dbEntity.ExpirationTime) // When cacheGUID is nil, ID should be kept and no originator info are filled. dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, nil, "client1") suite.Require().NoError(err, "CreateDBSyncEntity should succeed") - suite.Assert().Equal(dbEntity.ID, *pbEntity.IdString) - suite.Assert().Nil(dbEntity.OriginatorCacheGUID) - suite.Assert().Nil(dbEntity.OriginatorClientItemID) - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.Equal(dbEntity.ID, *pbEntity.IdString) + suite.Nil(dbEntity.OriginatorCacheGUID) + suite.Nil(dbEntity.OriginatorClientItemID) + suite.Nil(dbEntity.ExpirationTime) // Check that when updating from a previous version with guid, ID will not be // replaced. pbEntity.Version = aws.Int64(1) dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") suite.Require().NoError(err, "CreateDBSyncEntity should succeed") - suite.Assert().Equal(dbEntity.ID, *pbEntity.IdString) - suite.Assert().Nil(dbEntity.Deleted, "Deleted won't apply its default value for updated entities") - suite.Assert().Nil(dbEntity.Folder, "Deleted won't apply its default value for updated entities") - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.Equal(dbEntity.ID, *pbEntity.IdString) + suite.Nil(dbEntity.Deleted, "Deleted won't apply its default value for updated entities") + suite.Nil(dbEntity.Folder, "Deleted won't apply its default value for updated entities") + suite.Nil(dbEntity.ExpirationTime) // Empty unique position should be marshalled to nil without error. pbEntity.UniquePosition = nil dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") suite.Require().NoError(err) - suite.Assert().Nil(dbEntity.UniquePosition) - suite.Assert().Nil(dbEntity.ExpirationTime) + suite.Nil(dbEntity.UniquePosition) + suite.Nil(dbEntity.ExpirationTime) // A history entity should have the client tag hash as the ID, // and an expiration time. @@ -760,15 +760,15 @@ func (suite *SyncEntityTestSuite) TestCreateDBSyncEntity() { pbEntity.Specifics = &sync_pb.EntitySpecifics{SpecificsVariant: historyEntitySpecific} dbEntity, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") suite.Require().NoError(err) - suite.Assert().Equal(dbEntity.ID, "client_tag") + suite.Equal("client_tag", dbEntity.ID) expectedExpirationTime := time.Now().Unix() + datastore.HistoryExpirationIntervalSecs - suite.Assert().Greater(*dbEntity.ExpirationTime+2, expectedExpirationTime) - suite.Assert().Less(*dbEntity.ExpirationTime-2, expectedExpirationTime) + suite.Greater(*dbEntity.ExpirationTime+2, expectedExpirationTime) + suite.Less(*dbEntity.ExpirationTime-2, expectedExpirationTime) // Empty specifics should report marshal error. pbEntity.Specifics = nil _, err = datastore.CreateDBSyncEntity(&pbEntity, guid, "client1") - suite.Assert().NotNil(err.Error(), "empty specifics should fail") + suite.NotNil(err.Error(), "empty specifics should fail") } func (suite *SyncEntityTestSuite) TestCreatePBSyncEntity() { @@ -830,19 +830,19 @@ func (suite *SyncEntityTestSuite) TestCreatePBSyncEntity() { suite.Require().NoError(err, "json.Marshal should succeed") s2, err := json.Marshal(&expectedPBEntity) suite.Require().NoError(err, "json.Marshal should succeed") - suite.Assert().Equal(s1, s2) + suite.Equal(s1, s2) // Nil UniquePosition should be unmarshalled as nil without error. dbEntity.UniquePosition = nil pbEntity, err = datastore.CreatePBSyncEntity(&dbEntity) suite.Require().NoError(err, "CreatePBSyncEntity should succeed") - suite.Assert().Nil(pbEntity.UniquePosition) + suite.Nil(pbEntity.UniquePosition) // Nil Specifics should be unmarshalled as nil without error. dbEntity.Specifics = nil pbEntity, err = datastore.CreatePBSyncEntity(&dbEntity) suite.Require().NoError(err, "CreatePBSyncEntity should succeed") - suite.Assert().Nil(pbEntity.Specifics) + suite.Nil(pbEntity.Specifics) } func (suite *SyncEntityTestSuite) TestDisableSyncChain() { @@ -852,9 +852,9 @@ func (suite *SyncEntityTestSuite) TestDisableSyncChain() { suite.Require().NoError(err, "DisableSyncChain should succeed") e, err := datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(1, len(e)) - suite.Assert().Equal(clientID, e[0].ClientID) - suite.Assert().Equal(id, e[0].ID) + suite.Len(e, 1) + suite.Equal(clientID, e[0].ClientID) + suite.Equal(id, e[0].ID) } func (suite *SyncEntityTestSuite) TestIsSyncChainDisabled() { @@ -862,13 +862,13 @@ func (suite *SyncEntityTestSuite) TestIsSyncChainDisabled() { disabled, err := suite.dynamo.IsSyncChainDisabled(clientID) suite.Require().NoError(err, "IsSyncChainDisabled should succeed") - suite.Assert().Equal(false, disabled) + suite.False(disabled) err = suite.dynamo.DisableSyncChain(clientID) suite.Require().NoError(err, "DisableSyncChain should succeed") disabled, err = suite.dynamo.IsSyncChainDisabled(clientID) suite.Require().NoError(err, "IsSyncChainDisabled should succeed") - suite.Assert().Equal(true, disabled) + suite.True(disabled) } func (suite *SyncEntityTestSuite) TestClearServerData() { @@ -889,15 +889,15 @@ func (suite *SyncEntityTestSuite) TestClearServerData() { e, err := datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(1, len(e)) + suite.Len(e, 1) e, err = suite.dynamo.ClearServerData(entity.ClientID) suite.Require().NoError(err, "ClearServerData should succeed") - suite.Assert().Equal(1, len(e)) + suite.Len(e, 1) e, err = datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(0, len(e)) + suite.Empty(e) // Test clear tagged items entity1 := datastore.SyncEntity{ @@ -922,23 +922,23 @@ func (suite *SyncEntityTestSuite) TestClearServerData() { e, err = datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(2, len(e), "No items should be written if fail") + suite.Len(e, 2, "No items should be written if fail") t, err := datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(2, len(t), "No items should be written if fail") + suite.Len(t, 2, "No items should be written if fail") e, err = suite.dynamo.ClearServerData(entity.ClientID) suite.Require().NoError(err, "ClearServerData should succeed") - suite.Assert().Equal(4, len(e)) + suite.Len(e, 4) e, err = datastoretest.ScanSyncEntities(suite.dynamo) suite.Require().NoError(err, "ScanSyncEntities should succeed") - suite.Assert().Equal(0, len(e), "No items should be written if fail") + suite.Empty(e, "No items should be written if fail") t, err = datastoretest.ScanTagItems(suite.dynamo) suite.Require().NoError(err, "ScanTagItems should succeed") - suite.Assert().Equal(0, len(t), "No items should be written if fail") + suite.Empty(t, "No items should be written if fail") } func TestSyncEntityTestSuite(t *testing.T) { diff --git a/middleware/middleware_test.go b/middleware/middleware_test.go index b1665203..e3c4ece5 100644 --- a/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -43,7 +43,7 @@ func (suite *MiddlewareTestSuite) TestDisabledChainMiddleware() { ctx = context.WithValue(context.Background(), syncContext.ContextKeyClientID, clientID) ctx = context.WithValue(ctx, syncContext.ContextKeyDatastore, datastore) next = http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { - suite.Require().Equal(false, true) + suite.Fail("Should not reach this point") }) handler = middleware.DisabledChain(next) req, err = http.NewRequestWithContext(ctx, "POST", "v2/command/", bytes.NewBuffer([]byte{})) @@ -72,7 +72,7 @@ func (suite *MiddlewareTestSuite) TestAuthMiddleware() { next := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { ctx := r.Context() clientID := ctx.Value(syncContext.ContextKeyClientID) - suite.Require().NotNil(clientID, "Client ID should be set by auth middleware") + suite.NotNil(clientID, "Client ID should be set by auth middleware") }) handler := middleware.Auth(next) diff --git a/server/server_test.go b/server/server_test.go index 6e5b5876..62d2ce68 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -9,6 +9,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/brave/go-sync/server" ) @@ -25,7 +26,7 @@ func init() { func TestPing(t *testing.T) { req, err := http.NewRequest("GET", "/", nil) - assert.Nil(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() mux.ServeHTTP(rr, req.WithContext(serverCtx)) @@ -33,13 +34,13 @@ func TestPing(t *testing.T) { expected := "." actual, err := ioutil.ReadAll(rr.Result().Body) - assert.Nil(t, err) + require.NoError(t, err) assert.Equal(t, expected, string(actual)) } func TestCommand(t *testing.T) { req, err := http.NewRequest("POST", "/v2/command/", nil) - assert.Nil(t, err) + require.NoError(t, err) rr := httptest.NewRecorder() mux.ServeHTTP(rr, req.WithContext(serverCtx)) From 7ae33dae801019423faafecd37b4d1c825400210 Mon Sep 17 00:00:00 2001 From: mschfh <37435502+mschfh@users.noreply.github.com> Date: Wed, 29 Oct 2025 06:13:58 -0500 Subject: [PATCH 5/5] refactor: replace deprecated io/ioutil --- controller/controller.go | 3 +-- datastore/datastoretest/dynamo.go | 4 ++-- server/server_test.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 3f4422e1..e3564908 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -3,7 +3,6 @@ package controller import ( "compress/gzip" "io" - "io/ioutil" "net/http" "github.com/brave-intl/bat-go/libs/closers" @@ -56,7 +55,7 @@ func Command(cache *cache.Cache, db datastore.Datastore) http.HandlerFunc { reader = gr } - msg, err := ioutil.ReadAll(io.LimitReader(reader, payloadLimit10MB)) + msg, err := io.ReadAll(io.LimitReader(reader, payloadLimit10MB)) if err != nil { log.Error().Err(err).Msg("Read request body failed") http.Error(w, "Read request body error", http.StatusInternalServerError) diff --git a/datastore/datastoretest/dynamo.go b/datastore/datastoretest/dynamo.go index 3828c505..7cbbdc70 100644 --- a/datastore/datastoretest/dynamo.go +++ b/datastore/datastoretest/dynamo.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "runtime" "time" @@ -43,7 +43,7 @@ func DeleteTable(dynamo *datastore.Dynamo) error { func CreateTable(dynamo *datastore.Dynamo) error { _, b, _, _ := runtime.Caller(0) root := filepath.Join(filepath.Dir(b), "../../") - raw, err := ioutil.ReadFile(filepath.Join(root, "schema/dynamodb/table.json")) + raw, err := os.ReadFile(filepath.Join(root, "schema/dynamodb/table.json")) if err != nil { return fmt.Errorf("error reading table.json: %w", err) } diff --git a/server/server_test.go b/server/server_test.go index 62d2ce68..abf9e568 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -2,7 +2,7 @@ package server_test import ( "context" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -33,7 +33,7 @@ func TestPing(t *testing.T) { assert.Equal(t, http.StatusOK, rr.Code) expected := "." - actual, err := ioutil.ReadAll(rr.Result().Body) + actual, err := io.ReadAll(rr.Result().Body) require.NoError(t, err) assert.Equal(t, expected, string(actual)) }