Skip to content

Commit

Permalink
PR - Migrate golang/mock to uber-go/mock (#7566)
Browse files Browse the repository at this point in the history
# Migrate golang/mock to uber-go/mock

* Changed references/import to replace golang/mock with user-go
* Change mockgen tooling in workflow, makefile and DevContainer
* Updates docs that reference golang package

## Type of change

- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of
Radius.


Fixes: #7543

---------

Signed-off-by: gpltaylor <gpltaylor@gmail.com>
Co-authored-by: Ryan Nowak <nowakra@gmail.com>
  • Loading branch information
gpltaylor and rynowak committed May 6, 2024
1 parent cf37fbd commit 4d7ee44
Show file tree
Hide file tree
Showing 173 changed files with 516 additions and 335 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/contributor/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
// Prerequisite for Code Generation, see https://github.com/radius-project/radius/tree/main/docs/contributing/contributing-code/contributing-code-prerequisites#code-generation
// Adding workspace as safe directory to avoid permission issues
"postCreateCommand": "git config --global --add safe.directory /workspaces/radius && cd typespec && npm ci && npm install -g autorest && npm install -g oav && go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0 && go install github.com/golang/mock/mockgen@v1.5.0",
"postCreateCommand": "git config --global --add safe.directory /workspaces/radius && cd typespec && npm ci && npm install -g autorest && npm install -g oav && go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0 && go install go.uber.org/mock/mockgen@v0.4.0",
"hostRequirements": {
"memory": "8gb"
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install oav
run: npm install -g oav@3.2.0
- name: Install mockgen
run: go install github.com/golang/mock/mockgen@v1.5.0
run: go install go.uber.org/mock/mockgen@v0.4.0
- name: Install controller-gen
run: go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0
- name: Install helm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install mockgen
run: |
cd radius
go install github.com/golang/mock/mockgen@v1.5.0
go install go.uber.org/mock/mockgen@v0.4.0
- name: Install controller-gen
run: |
cd radius
Expand Down
2 changes: 1 addition & 1 deletion build/generate.mk
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ generate-rad-ucp-client: generate-node-installed generate-autorest-installed tes
.PHONY: generate-mockgen-installed
generate-mockgen-installed:
@echo "$(ARROW) Detecting mockgen..."
@which mockgen > /dev/null || { echo "run 'go install github.com/golang/mock/mockgen@v1.5.0' to install mockgen"; exit 1; }
@which mockgen > /dev/null || { echo "run 'go install go.uber.org/mock/mockgen@v0.4.0' to install mockgen"; exit 1; }
@echo "$(ARROW) OK"

.PHONY: generate-go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ cd typespec && npm ci
npm install -g autorest
npm install -g oav
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0
go install github.com/golang/mock/mockgen@v1.5.0
go install go.uber.org/mock/mockgen@v0.4.0
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ require (
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.19.0
github.com/gofrs/flock v0.8.1
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gosuri/uilive v0.0.4
Expand Down Expand Up @@ -76,6 +75,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.25.0
go.opentelemetry.io/otel/trace v1.25.0
go.uber.org/atomic v1.11.0
go.uber.org/mock v0.4.0
go.uber.org/zap v1.27.0
golang.org/x/sync v0.7.0
golang.org/x/text v0.14.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
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/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -1065,6 +1064,8 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
Expand Down
15 changes: 10 additions & 5 deletions pkg/armrpc/asyncoperation/statusmanager/mock_statusmanager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/google/uuid"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
"github.com/radius-project/radius/pkg/armrpc/rpctest"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/resources"
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

type asyncOperationsManagerTest struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/asyncoperation/worker/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
ctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller"
"github.com/radius-project/radius/pkg/corerp/backend/deployment"
"github.com/radius-project/radius/pkg/ucp/dataprovider"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestRegister_Get(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/google/uuid"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
ctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller"
Expand All @@ -37,6 +36,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"go.uber.org/mock/gomock"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/asyncoperation/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"testing"
"time"

"github.com/golang/mock/gomock"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestDefaultOptions(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"testing"

"github.com/go-chi/chi/v5"
"github.com/golang/mock/gomock"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
asyncctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller"
"github.com/radius-project/radius/pkg/armrpc/asyncoperation/worker"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/test/testcontext"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

var handlerTests = []rpctest.HandlerTestSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/radius-project/radius/pkg/armrpc/rpctest"
"github.com/radius-project/radius/pkg/ucp/store"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestDefaultAsyncDelete(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/test/testutil"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestDefaultAsyncPut_Create(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/radius-project/radius/pkg/armrpc/rpctest"
"github.com/radius-project/radius/pkg/ucp/store"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestDefaultSyncDelete(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/test/testutil"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestDefaultSyncPut_Create(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/radius-project/radius/test/testcontext"
"github.com/radius-project/radius/test/testutil"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestGetOperationResultRun(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/test/testutil"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func TestGetOperationStatusRun(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/frontend/defaultoperation/getresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/radius-project/radius/pkg/armrpc/rpctest"
"github.com/radius-project/radius/pkg/ucp/store"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

type testDataModel struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/frontend/defaultoperation/listresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/radius-project/radius/pkg/armrpc/rpctest"
"github.com/radius-project/radius/pkg/ucp/store"

"github.com/golang/mock/gomock"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

type testResourceList struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/frontend/defaultoperation/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/test/testutil"

"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/frontend/server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"testing"

"github.com/go-chi/chi/v5"
"github.com/golang/mock/gomock"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
ctrl "github.com/radius-project/radius/pkg/armrpc/frontend/controller"
"github.com/radius-project/radius/pkg/armrpc/rest"
Expand All @@ -36,6 +35,7 @@ import (
"github.com/radius-project/radius/pkg/ucp/dataprovider"
"github.com/radius-project/radius/test/testcontext"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)

func Test_NewSubrouter(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/rpctest/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"encoding/json"
"testing"

"github.com/golang/mock/gomock"
v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
"github.com/radius-project/radius/pkg/ucp/dataprovider"
"github.com/radius-project/radius/pkg/ucp/store"
"go.uber.org/mock/gomock"
)

// ControllerContext represents the context of controller tests including common mocks.
Expand Down
11 changes: 8 additions & 3 deletions pkg/cli/aws/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4d7ee44

Please sign in to comment.