From 956a5ad029f02a6d022c6af1bb3d373f3347a471 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 31 Aug 2024 17:44:48 +0800 Subject: [PATCH 1/3] chore(mock): migrate mock package and enhance clarity in tests - Update dependency from `github.com/golang/mock` to `go.uber.org/mock` - Remove unused import from `mocks/mocks.go` - Change parameter type from `interface{}` to `any` in mock recorder functions - Add generated comments in mock files for clarity - Adjust import statements in test files to reflect the new mock package Signed-off-by: appleboy --- go.mod | 2 +- go.sum | 27 ++------------------------- mocks/mock_message.go | 7 ++++++- mocks/mock_worker.go | 11 ++++++++--- mocks/mocks.go | 2 -- queue_test.go | 2 +- ring_test.go | 2 +- 7 files changed, 19 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index 6f38085..6ec3383 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.20 require ( github.com/appleboy/com v0.1.7 - github.com/golang/mock v1.6.0 github.com/jpillora/backoff v1.0.0 github.com/stretchr/testify v1.8.4 go.uber.org/goleak v1.2.1 + go.uber.org/mock v0.4.0 ) require ( diff --git a/go.sum b/go.sum index 2e8c6b5..f03cc91 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/appleboy/com v0.1.7/go.mod h1:JUK+oH0SXCLRH57pDMJx6VWVsm8CPdajalmRSWw github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -14,31 +12,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/mocks/mock_message.go b/mocks/mock_message.go index 13d4e2c..ce6f18c 100644 --- a/mocks/mock_message.go +++ b/mocks/mock_message.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/golang-queue/queue/core (interfaces: QueuedMessage) +// +// Generated by this command: +// +// mockgen -package=mocks -destination=mock_message.go github.com/golang-queue/queue/core QueuedMessage +// // Package mocks is a generated GoMock package. package mocks @@ -7,7 +12,7 @@ package mocks import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockQueuedMessage is a mock of QueuedMessage interface. diff --git a/mocks/mock_worker.go b/mocks/mock_worker.go index 5440693..16c7c5d 100644 --- a/mocks/mock_worker.go +++ b/mocks/mock_worker.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/golang-queue/queue/core (interfaces: Worker) +// +// Generated by this command: +// +// mockgen -package=mocks -destination=mock_worker.go github.com/golang-queue/queue/core Worker +// // Package mocks is a generated GoMock package. package mocks @@ -9,7 +14,7 @@ import ( reflect "reflect" core "github.com/golang-queue/queue/core" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockWorker is a mock of Worker interface. @@ -44,7 +49,7 @@ func (m *MockWorker) Queue(arg0 core.QueuedMessage) error { } // Queue indicates an expected call of Queue. -func (mr *MockWorkerMockRecorder) Queue(arg0 interface{}) *gomock.Call { +func (mr *MockWorkerMockRecorder) Queue(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Queue", reflect.TypeOf((*MockWorker)(nil).Queue), arg0) } @@ -73,7 +78,7 @@ func (m *MockWorker) Run(arg0 context.Context, arg1 core.QueuedMessage) error { } // Run indicates an expected call of Run. -func (mr *MockWorkerMockRecorder) Run(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockWorkerMockRecorder) Run(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockWorker)(nil).Run), arg0, arg1) } diff --git a/mocks/mocks.go b/mocks/mocks.go index f87860c..e170390 100644 --- a/mocks/mocks.go +++ b/mocks/mocks.go @@ -1,6 +1,4 @@ package mocks -import _ "github.com/golang/mock/mockgen/model" - //go:generate mockgen -package=mocks -destination=mock_worker.go github.com/golang-queue/queue/core Worker //go:generate mockgen -package=mocks -destination=mock_message.go github.com/golang-queue/queue/core QueuedMessage diff --git a/queue_test.go b/queue_test.go index 7c6fb9e..c97e221 100644 --- a/queue_test.go +++ b/queue_test.go @@ -11,9 +11,9 @@ import ( "github.com/golang-queue/queue/job" "github.com/golang-queue/queue/mocks" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "go.uber.org/goleak" + "go.uber.org/mock/gomock" ) func TestMain(m *testing.M) { diff --git a/ring_test.go b/ring_test.go index b3f90a7..996e9f8 100644 --- a/ring_test.go +++ b/ring_test.go @@ -13,8 +13,8 @@ import ( "github.com/golang-queue/queue/job" "github.com/golang-queue/queue/mocks" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func TestMaxCapacity(t *testing.T) { From fa579ccb58bb13c6dcacf5a4d54330fac4727584 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 31 Aug 2024 17:46:57 +0800 Subject: [PATCH 2/3] ci: update CI configuration for Ubuntu-only builds - Change the operating system matrix to only include `ubuntu-latest` Signed-off-by: appleboy --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ae9e0a6..148cf24 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -38,7 +38,7 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest] go: ["1.20", 1.21, 1.22, 1.23] include: - os: ubuntu-latest From 233524fdacc3978f46b75326453c3339846cf925 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 31 Aug 2024 17:58:52 +0800 Subject: [PATCH 3/3] ci: upgrade golangci-lint action to version 6 - Update golangci-lint action version from v4 to v6 Signed-off-by: appleboy --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 148cf24..779a6bc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,7 +31,7 @@ jobs: go-version-file: "go.mod" check-latest: true - name: Setup golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: version: latest args: --verbose