diff --git a/Makefile b/Makefile index bef843f6542..20de404a424 100644 --- a/Makefile +++ b/Makefile @@ -381,7 +381,7 @@ modfix: .PHONY: install-tools install-tools: - go install $(GO_MOD_FLAGS) github.com/golang/mock/mockgen + go install $(GO_MOD_FLAGS) go.uber.org/mock/mockgen@v0.6.0 go install $(GO_MOD_FLAGS) golang.org/x/lint/golint go install $(GO_MOD_FLAGS) github.com/golangci/golangci-lint/cmd/golangci-lint diff --git a/docs/developing.md b/docs/developing.md index febc6a6dda9..9ddbbba78cd 100644 --- a/docs/developing.md +++ b/docs/developing.md @@ -46,7 +46,7 @@ - [kustomize](https://github.com/kubernetes-sigs/kustomize#kustomize) - [imagebuilder](https://github.com/openshift/imagebuilder) -- [mockgen](https://github.com/golang/mock) +- [mockgen](https://github.com/uber-go/mock) ## Build and run tests diff --git a/go.mod b/go.mod index 09152e39092..fab80829e56 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,6 @@ require ( github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-bindata/go-bindata v3.1.2+incompatible github.com/go-logr/logr v1.4.2 - github.com/golang/mock v1.7.0-rc.1 github.com/golangci/golangci-lint v1.64.5 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 @@ -52,6 +51,7 @@ require ( github.com/stretchr/testify v1.10.0 github.com/tidwall/gjson v1.14.3 github.com/vmware/govmomi v0.47.1 + go.uber.org/mock v0.6.0 golang.org/x/crypto v0.43.0 golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 golang.org/x/mod v0.28.0 diff --git a/go.sum b/go.sum index ca7009a4505..4491d40455b 100644 --- a/go.sum +++ b/go.sum @@ -1065,8 +1065,8 @@ go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= 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.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= -go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= @@ -1096,7 +1096,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -1205,7 +1204,6 @@ golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0t golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= diff --git a/pkg/awsclient/mock/client_generated.go b/pkg/awsclient/mock/client_generated.go index 1665a5e138a..6b09beee223 100644 --- a/pkg/awsclient/mock/client_generated.go +++ b/pkg/awsclient/mock/client_generated.go @@ -15,7 +15,7 @@ import ( route53 "github.com/aws/aws-sdk-go-v2/service/route53" s3 "github.com/aws/aws-sdk-go-v2/service/s3" sts "github.com/aws/aws-sdk-go-v2/service/sts" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockClient is a mock of Client interface. diff --git a/pkg/azureclient/mock/client_generated.go b/pkg/azureclient/mock/client_generated.go index 541cb5b98fe..510ad11045a 100644 --- a/pkg/azureclient/mock/client_generated.go +++ b/pkg/azureclient/mock/client_generated.go @@ -10,8 +10,8 @@ import ( compute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" dns "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" - gomock "github.com/golang/mock/gomock" azureclient "github.com/openshift/hive/pkg/azureclient" + gomock "go.uber.org/mock/gomock" ) // MockClient is a mock of Client interface. diff --git a/pkg/controller/awsprivatelink/awsprivatelink_controller_test.go b/pkg/controller/awsprivatelink/awsprivatelink_controller_test.go index e7462ca56d0..e239a9015d5 100644 --- a/pkg/controller/awsprivatelink/awsprivatelink_controller_test.go +++ b/pkg/controller/awsprivatelink/awsprivatelink_controller_test.go @@ -16,11 +16,11 @@ import ( route53types "github.com/aws/aws-sdk-go-v2/service/route53/types" "github.com/aws/aws-sdk-go-v2/service/sts" "github.com/davecgh/go-spew/spew" - "github.com/golang/mock/gomock" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/awsprivatelink/cleanup_test.go b/pkg/controller/awsprivatelink/cleanup_test.go index cb03ef2768c..8369be90e06 100644 --- a/pkg/controller/awsprivatelink/cleanup_test.go +++ b/pkg/controller/awsprivatelink/cleanup_test.go @@ -6,9 +6,9 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" hivev1 "github.com/openshift/hive/apis/hive/v1" hivev1aws "github.com/openshift/hive/apis/hive/v1/aws" diff --git a/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go b/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go index 80d595dd880..47315b8d85c 100644 --- a/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go +++ b/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go @@ -30,7 +30,6 @@ import ( testfake "github.com/openshift/hive/pkg/test/fake" "github.com/openshift/hive/pkg/util/scheme" - "github.com/golang/mock/gomock" configv1 "github.com/openshift/api/config/v1" routev1 "github.com/openshift/api/route/v1" librarygocontroller "github.com/openshift/library-go/pkg/controller" @@ -40,6 +39,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "golang.org/x/crypto/openpgp" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/clusterdeprovision/clusterdeprovision_controller_test.go b/pkg/controller/clusterdeprovision/clusterdeprovision_controller_test.go index ec86d6886e6..39ee03c9135 100644 --- a/pkg/controller/clusterdeprovision/clusterdeprovision_controller_test.go +++ b/pkg/controller/clusterdeprovision/clusterdeprovision_controller_test.go @@ -4,10 +4,10 @@ import ( "context" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/clusterdeprovision/helpers_test.go b/pkg/controller/clusterdeprovision/helpers_test.go index 75435b59ef5..0ab25f45b12 100644 --- a/pkg/controller/clusterdeprovision/helpers_test.go +++ b/pkg/controller/clusterdeprovision/helpers_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/controller/clusterrelocate/clusterrelocate_controller_test.go b/pkg/controller/clusterrelocate/clusterrelocate_controller_test.go index 01cebf6c833..ff9f66f0ec3 100644 --- a/pkg/controller/clusterrelocate/clusterrelocate_controller_test.go +++ b/pkg/controller/clusterrelocate/clusterrelocate_controller_test.go @@ -6,10 +6,10 @@ import ( "reflect" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/clusterstate/clusterstate_controller_test.go b/pkg/controller/clusterstate/clusterstate_controller_test.go index 944c7550669..a6e894ad564 100644 --- a/pkg/controller/clusterstate/clusterstate_controller_test.go +++ b/pkg/controller/clusterstate/clusterstate_controller_test.go @@ -5,10 +5,10 @@ import ( "sort" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" diff --git a/pkg/controller/clustersync/clustersync_controller_test.go b/pkg/controller/clustersync/clustersync_controller_test.go index 1cdec6efb66..49d62705faa 100644 --- a/pkg/controller/clustersync/clustersync_controller_test.go +++ b/pkg/controller/clustersync/clustersync_controller_test.go @@ -8,11 +8,11 @@ import ( "time" jsonpatch "github.com/evanphx/json-patch" - "github.com/golang/mock/gomock" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "k8s.io/utils/ptr" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/clusterversion/clusterversion_controller_test.go b/pkg/controller/clusterversion/clusterversion_controller_test.go index 6c240002b9a..573f9235700 100644 --- a/pkg/controller/clusterversion/clusterversion_controller_test.go +++ b/pkg/controller/clusterversion/clusterversion_controller_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/dnsendpoint/dnsendpoint_controller_test.go b/pkg/controller/dnsendpoint/dnsendpoint_controller_test.go index dfa1984a999..170b3a63aea 100644 --- a/pkg/controller/dnsendpoint/dnsendpoint_controller_test.go +++ b/pkg/controller/dnsendpoint/dnsendpoint_controller_test.go @@ -9,11 +9,11 @@ import ( "time" "github.com/go-logr/logr" - "github.com/golang/mock/gomock" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/pkg/controller/dnsendpoint/nameserver/aws_test.go b/pkg/controller/dnsendpoint/nameserver/aws_test.go index c1079c8bf06..a2d646f23b0 100644 --- a/pkg/controller/dnsendpoint/nameserver/aws_test.go +++ b/pkg/controller/dnsendpoint/nameserver/aws_test.go @@ -6,8 +6,8 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/route53" route53types "github.com/aws/aws-sdk-go-v2/service/route53/types" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/util/sets" diff --git a/pkg/controller/dnsendpoint/nameserver/azure_test.go b/pkg/controller/dnsendpoint/nameserver/azure_test.go index 7668f2ee6ad..65e05336141 100644 --- a/pkg/controller/dnsendpoint/nameserver/azure_test.go +++ b/pkg/controller/dnsendpoint/nameserver/azure_test.go @@ -5,8 +5,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/Azure/go-autorest/autorest/to" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/util/sets" diff --git a/pkg/controller/dnsendpoint/nameserver/gcp_test.go b/pkg/controller/dnsendpoint/nameserver/gcp_test.go index a6ae83619e3..f3a7800e5d3 100644 --- a/pkg/controller/dnsendpoint/nameserver/gcp_test.go +++ b/pkg/controller/dnsendpoint/nameserver/gcp_test.go @@ -3,8 +3,8 @@ package nameserver import ( "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" dns "google.golang.org/api/dns/v1" "k8s.io/apimachinery/pkg/util/sets" diff --git a/pkg/controller/dnsendpoint/nameserver/mock/query_generated.go b/pkg/controller/dnsendpoint/nameserver/mock/query_generated.go index b710be7d078..41854f70214 100644 --- a/pkg/controller/dnsendpoint/nameserver/mock/query_generated.go +++ b/pkg/controller/dnsendpoint/nameserver/mock/query_generated.go @@ -7,7 +7,7 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" sets "k8s.io/apimachinery/pkg/util/sets" ) diff --git a/pkg/controller/dnsendpoint/nameserverscraper_test.go b/pkg/controller/dnsendpoint/nameserverscraper_test.go index 922284fd250..dc421f71aa8 100644 --- a/pkg/controller/dnsendpoint/nameserverscraper_test.go +++ b/pkg/controller/dnsendpoint/nameserverscraper_test.go @@ -5,10 +5,10 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/util/sets" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/controller/dnszone/awsactuator_test.go b/pkg/controller/dnszone/awsactuator_test.go index 4b03d188525..d7476db4407 100644 --- a/pkg/controller/dnszone/awsactuator_test.go +++ b/pkg/controller/dnszone/awsactuator_test.go @@ -10,9 +10,9 @@ import ( "github.com/aws/aws-sdk-go-v2/service/route53" route53types "github.com/aws/aws-sdk-go-v2/service/route53/types" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" hivev1 "github.com/openshift/hive/apis/hive/v1" "github.com/openshift/hive/pkg/awsclient" diff --git a/pkg/controller/dnszone/azureactuator_test.go b/pkg/controller/dnszone/azureactuator_test.go index 181664dfb79..1bb0994bbc5 100644 --- a/pkg/controller/dnszone/azureactuator_test.go +++ b/pkg/controller/dnszone/azureactuator_test.go @@ -8,9 +8,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/to" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/dnszone/dnszone_controller_test.go b/pkg/controller/dnszone/dnszone_controller_test.go index 4cc35a95419..a5368126dde 100644 --- a/pkg/controller/dnszone/dnszone_controller_test.go +++ b/pkg/controller/dnszone/dnszone_controller_test.go @@ -5,9 +5,9 @@ import ( "fmt" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/pkg/controller/dnszone/gcpactuator_test.go b/pkg/controller/dnszone/gcpactuator_test.go index 94046f3ebed..dee0b303c32 100644 --- a/pkg/controller/dnszone/gcpactuator_test.go +++ b/pkg/controller/dnszone/gcpactuator_test.go @@ -3,11 +3,11 @@ package dnszone import ( "testing" - "github.com/golang/mock/gomock" hivev1 "github.com/openshift/hive/apis/hive/v1" "github.com/openshift/hive/pkg/gcpclient/mock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" dns "google.golang.org/api/dns/v1" "google.golang.org/api/googleapi" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/dnszone/test_helpers.go b/pkg/controller/dnszone/test_helpers.go index e25ae1a4a98..92779454175 100644 --- a/pkg/controller/dnszone/test_helpers.go +++ b/pkg/controller/dnszone/test_helpers.go @@ -16,11 +16,11 @@ import ( gcpclient "github.com/openshift/hive/pkg/gcpclient" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/golang/mock/gomock" mockaws "github.com/openshift/hive/pkg/awsclient/mock" mockazure "github.com/openshift/hive/pkg/azureclient/mock" mockgcp "github.com/openshift/hive/pkg/gcpclient/mock" testfake "github.com/openshift/hive/pkg/test/fake" + "go.uber.org/mock/gomock" ) var ( diff --git a/pkg/controller/hibernation/aws_actuator_test.go b/pkg/controller/hibernation/aws_actuator_test.go index 48caf20ffda..c623ffaffb0 100644 --- a/pkg/controller/hibernation/aws_actuator_test.go +++ b/pkg/controller/hibernation/aws_actuator_test.go @@ -9,10 +9,10 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/hibernation/azure_actuator_test.go b/pkg/controller/hibernation/azure_actuator_test.go index 38cb6a0f618..89fbcfeb54e 100644 --- a/pkg/controller/hibernation/azure_actuator_test.go +++ b/pkg/controller/hibernation/azure_actuator_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/controller/hibernation/gcp_actuator_test.go b/pkg/controller/hibernation/gcp_actuator_test.go index 1a539bd6b2e..0a27157162f 100644 --- a/pkg/controller/hibernation/gcp_actuator_test.go +++ b/pkg/controller/hibernation/gcp_actuator_test.go @@ -4,10 +4,10 @@ import ( "fmt" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" compute "google.golang.org/api/compute/v1" "k8s.io/utils/ptr" diff --git a/pkg/controller/hibernation/hibernation_controller_test.go b/pkg/controller/hibernation/hibernation_controller_test.go index 095a2dbb68c..7cb23e872e4 100644 --- a/pkg/controller/hibernation/hibernation_controller_test.go +++ b/pkg/controller/hibernation/hibernation_controller_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" certsv1 "k8s.io/api/certificates/v1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/hibernation/ibmcloud_actuator_test.go b/pkg/controller/hibernation/ibmcloud_actuator_test.go index 4873bc0f158..ba4ac79bb54 100644 --- a/pkg/controller/hibernation/ibmcloud_actuator_test.go +++ b/pkg/controller/hibernation/ibmcloud_actuator_test.go @@ -8,10 +8,10 @@ import ( "testing" "github.com/IBM/vpc-go-sdk/vpcv1" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/controller/hibernation/mock/csr_helper_generated.go b/pkg/controller/hibernation/mock/csr_helper_generated.go index b2d2345a515..be3a5f40c66 100644 --- a/pkg/controller/hibernation/mock/csr_helper_generated.go +++ b/pkg/controller/hibernation/mock/csr_helper_generated.go @@ -8,8 +8,8 @@ import ( x509 "crypto/x509" reflect "reflect" - gomock "github.com/golang/mock/gomock" v1beta1 "github.com/openshift/api/machine/v1beta1" + gomock "go.uber.org/mock/gomock" v1 "k8s.io/api/certificates/v1" kubernetes "k8s.io/client-go/kubernetes" ) diff --git a/pkg/controller/hibernation/mock/hibernation_actuator_generated.go b/pkg/controller/hibernation/mock/hibernation_actuator_generated.go index 249c3884302..9d4a356f4d8 100644 --- a/pkg/controller/hibernation/mock/hibernation_actuator_generated.go +++ b/pkg/controller/hibernation/mock/hibernation_actuator_generated.go @@ -7,9 +7,9 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" v1 "github.com/openshift/hive/apis/hive/v1" logrus "github.com/sirupsen/logrus" + gomock "go.uber.org/mock/gomock" client "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/pkg/controller/machinepool/awsactuator_test.go b/pkg/controller/machinepool/awsactuator_test.go index fa90755a423..b26e08655d7 100644 --- a/pkg/controller/machinepool/awsactuator_test.go +++ b/pkg/controller/machinepool/awsactuator_test.go @@ -10,11 +10,11 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" - "github.com/golang/mock/gomock" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/controller/machinepool/azureactuator_test.go b/pkg/controller/machinepool/azureactuator_test.go index 1fda67bc181..4ffaee0d502 100644 --- a/pkg/controller/machinepool/azureactuator_test.go +++ b/pkg/controller/machinepool/azureactuator_test.go @@ -8,8 +8,8 @@ import ( "github.com/openshift/hive/pkg/constants" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" "k8s.io/utils/ptr" diff --git a/pkg/controller/machinepool/gcpactuator_test.go b/pkg/controller/machinepool/gcpactuator_test.go index a3227e8cb19..127328d52e5 100644 --- a/pkg/controller/machinepool/gcpactuator_test.go +++ b/pkg/controller/machinepool/gcpactuator_test.go @@ -6,10 +6,10 @@ import ( "fmt" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" compute "google.golang.org/api/compute/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/machinepool/ibmcloudactuator_test.go b/pkg/controller/machinepool/ibmcloudactuator_test.go index ed784eb5ccd..864e00e9684 100644 --- a/pkg/controller/machinepool/ibmcloudactuator_test.go +++ b/pkg/controller/machinepool/ibmcloudactuator_test.go @@ -4,10 +4,10 @@ import ( "fmt" "testing" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" diff --git a/pkg/controller/machinepool/machinepool_controller_test.go b/pkg/controller/machinepool/machinepool_controller_test.go index 1e4cdb6e646..578e4848fc6 100644 --- a/pkg/controller/machinepool/machinepool_controller_test.go +++ b/pkg/controller/machinepool/machinepool_controller_test.go @@ -12,10 +12,10 @@ import ( "github.com/openshift/hive/pkg/util/scheme" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/machinepool/mock/actuator_generated.go b/pkg/controller/machinepool/mock/actuator_generated.go index e873a4701e7..d30bf9b2417 100644 --- a/pkg/controller/machinepool/mock/actuator_generated.go +++ b/pkg/controller/machinepool/mock/actuator_generated.go @@ -7,10 +7,10 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" v1beta1 "github.com/openshift/api/machine/v1beta1" v1 "github.com/openshift/hive/apis/hive/v1" logrus "github.com/sirupsen/logrus" + gomock "go.uber.org/mock/gomock" ) // MockActuator is a mock of Actuator interface. diff --git a/pkg/controller/privatelink/actuator/awsactuator/awshubactuator_test.go b/pkg/controller/privatelink/actuator/awsactuator/awshubactuator_test.go index 1f02c933edc..8ca85e636c6 100644 --- a/pkg/controller/privatelink/actuator/awsactuator/awshubactuator_test.go +++ b/pkg/controller/privatelink/actuator/awsactuator/awshubactuator_test.go @@ -4,10 +4,10 @@ import ( "context" "testing" - "github.com/golang/mock/gomock" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" diff --git a/pkg/controller/privatelink/actuator/gcpactuator/gcplinkactuator_test.go b/pkg/controller/privatelink/actuator/gcpactuator/gcplinkactuator_test.go index 08a08a0ec90..57e6b3ea4f7 100644 --- a/pkg/controller/privatelink/actuator/gcpactuator/gcplinkactuator_test.go +++ b/pkg/controller/privatelink/actuator/gcpactuator/gcplinkactuator_test.go @@ -6,9 +6,9 @@ import ( "net/http" "testing" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" diff --git a/pkg/controller/privatelink/actuator/mock/actuator_generated.go b/pkg/controller/privatelink/actuator/mock/actuator_generated.go index 04024e27df0..2dccea75ea3 100644 --- a/pkg/controller/privatelink/actuator/mock/actuator_generated.go +++ b/pkg/controller/privatelink/actuator/mock/actuator_generated.go @@ -7,10 +7,10 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" v1 "github.com/openshift/hive/apis/hive/v1" actuator "github.com/openshift/hive/pkg/controller/privatelink/actuator" logrus "github.com/sirupsen/logrus" + gomock "go.uber.org/mock/gomock" reconcile "sigs.k8s.io/controller-runtime/pkg/reconcile" ) diff --git a/pkg/controller/privatelink/privatelink_test.go b/pkg/controller/privatelink/privatelink_test.go index 02faa8f8aa9..b62007a72a0 100644 --- a/pkg/controller/privatelink/privatelink_test.go +++ b/pkg/controller/privatelink/privatelink_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" diff --git a/pkg/controller/unreachable/unreachable_controller_test.go b/pkg/controller/unreachable/unreachable_controller_test.go index ce2dba5e8be..cd5ccd02ad2 100644 --- a/pkg/controller/unreachable/unreachable_controller_test.go +++ b/pkg/controller/unreachable/unreachable_controller_test.go @@ -21,9 +21,9 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/controller/velerobackup/velerobackup_controller_test.go b/pkg/controller/velerobackup/velerobackup_controller_test.go index ad9dd0de241..11fe3b70bae 100644 --- a/pkg/controller/velerobackup/velerobackup_controller_test.go +++ b/pkg/controller/velerobackup/velerobackup_controller_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" velerov1 "github.com/heptio/velero/pkg/apis/velero/v1" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" hivev1 "github.com/openshift/hive/apis/hive/v1" diff --git a/pkg/dependencymagnet/doc.go b/pkg/dependencymagnet/doc.go index 2f5e787b441..c53a0002a44 100644 --- a/pkg/dependencymagnet/doc.go +++ b/pkg/dependencymagnet/doc.go @@ -16,7 +16,7 @@ import ( // Used to generate bindata _ "github.com/go-bindata/go-bindata/go-bindata" // Used to generate mocks - _ "github.com/golang/mock/mockgen" + _ "go.uber.org/mock/mockgen" // Used to lint code _ "golang.org/x/lint/golint" // Used to lint code diff --git a/pkg/gcpclient/mock/client_generated.go b/pkg/gcpclient/mock/client_generated.go index 402869584f9..db1583d6e09 100644 --- a/pkg/gcpclient/mock/client_generated.go +++ b/pkg/gcpclient/mock/client_generated.go @@ -7,8 +7,8 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" gcpclient "github.com/openshift/hive/pkg/gcpclient" + gomock "go.uber.org/mock/gomock" compute "google.golang.org/api/compute/v1" dns "google.golang.org/api/dns/v1" ) diff --git a/pkg/ibmclient/mock/client_generated.go b/pkg/ibmclient/mock/client_generated.go index 79e40da4d39..aaf510f85f4 100644 --- a/pkg/ibmclient/mock/client_generated.go +++ b/pkg/ibmclient/mock/client_generated.go @@ -13,8 +13,8 @@ import ( resourcecontrollerv2 "github.com/IBM/platform-services-go-sdk/resourcecontrollerv2" resourcemanagerv2 "github.com/IBM/platform-services-go-sdk/resourcemanagerv2" vpcv1 "github.com/IBM/vpc-go-sdk/vpcv1" - gomock "github.com/golang/mock/gomock" ibmclient "github.com/openshift/hive/pkg/ibmclient" + gomock "go.uber.org/mock/gomock" ) // MockAPI is a mock of API interface. diff --git a/pkg/installmanager/helper_test.go b/pkg/installmanager/helper_test.go index 2e976b9d3b1..a2e054267fe 100644 --- a/pkg/installmanager/helper_test.go +++ b/pkg/installmanager/helper_test.go @@ -3,9 +3,9 @@ package installmanager import ( "testing" - "github.com/golang/mock/gomock" mockaws "github.com/openshift/hive/pkg/awsclient/mock" testfake "github.com/openshift/hive/pkg/test/fake" + "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/installmanager/ibm_metadata_test.go b/pkg/installmanager/ibm_metadata_test.go index 92cf65a307b..1c48f7cfd18 100644 --- a/pkg/installmanager/ibm_metadata_test.go +++ b/pkg/installmanager/ibm_metadata_test.go @@ -5,10 +5,10 @@ import ( "testing" "github.com/IBM/platform-services-go-sdk/iamidentityv1" - "github.com/golang/mock/gomock" "github.com/openshift/hive/pkg/ibmclient" mockibm "github.com/openshift/hive/pkg/ibmclient/mock" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" "k8s.io/utils/ptr" ) diff --git a/pkg/installmanager/s3loguploaderactuator_test.go b/pkg/installmanager/s3loguploaderactuator_test.go index e37d05b2a6c..d77666142c5 100644 --- a/pkg/installmanager/s3loguploaderactuator_test.go +++ b/pkg/installmanager/s3loguploaderactuator_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" "sigs.k8s.io/controller-runtime/pkg/client" log "github.com/sirupsen/logrus" diff --git a/pkg/remoteclient/mock/remoteclient_generated.go b/pkg/remoteclient/mock/remoteclient_generated.go index 5233321885f..e03b5db4e8c 100644 --- a/pkg/remoteclient/mock/remoteclient_generated.go +++ b/pkg/remoteclient/mock/remoteclient_generated.go @@ -7,8 +7,8 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" remoteclient "github.com/openshift/hive/pkg/remoteclient" + gomock "go.uber.org/mock/gomock" dynamic "k8s.io/client-go/dynamic" kubernetes "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" diff --git a/pkg/resource/mock/helper_generated.go b/pkg/resource/mock/helper_generated.go index f9030fb90e1..4d894c291fb 100644 --- a/pkg/resource/mock/helper_generated.go +++ b/pkg/resource/mock/helper_generated.go @@ -7,8 +7,8 @@ package mock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" resource "github.com/openshift/hive/pkg/resource" + gomock "go.uber.org/mock/gomock" runtime "k8s.io/apimachinery/pkg/runtime" types "k8s.io/apimachinery/pkg/types" ) diff --git a/pkg/test/manager/mock/manager_generated.go b/pkg/test/manager/mock/manager_generated.go index 37eed6ae62a..624ad665a95 100644 --- a/pkg/test/manager/mock/manager_generated.go +++ b/pkg/test/manager/mock/manager_generated.go @@ -10,7 +10,7 @@ import ( reflect "reflect" logr "github.com/go-logr/logr" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" meta "k8s.io/apimachinery/pkg/api/meta" runtime "k8s.io/apimachinery/pkg/runtime" rest "k8s.io/client-go/rest" diff --git a/vendor/github.com/golang/mock/CONTRIBUTORS b/vendor/github.com/golang/mock/CONTRIBUTORS deleted file mode 100644 index def849cab1b..00000000000 --- a/vendor/github.com/golang/mock/CONTRIBUTORS +++ /dev/null @@ -1,37 +0,0 @@ -# This is the official list of people who can contribute (and typically -# have contributed) code to the gomock repository. -# The AUTHORS file lists the copyright holders; this file -# lists people. For example, Google employees are listed here -# but not in AUTHORS, because Google holds the copyright. -# -# The submission process automatically checks to make sure -# that people submitting code are listed in this file (by email address). -# -# Names should be added to this file only after verifying that -# the individual or the individual's organization has agreed to -# the appropriate Contributor License Agreement, found here: -# -# http://code.google.com/legal/individual-cla-v1.0.html -# http://code.google.com/legal/corporate-cla-v1.0.html -# -# The agreement for individuals can be filled out on the web. -# -# When adding J Random Contributor's name to this file, -# either J's name or J's organization's name should be -# added to the AUTHORS file, depending on whether the -# individual or corporate CLA was used. - -# Names should be added to this file like so: -# Name -# -# An entry with two email addresses specifies that the -# first address should be used in the submit logs and -# that the second address should be recognized as the -# same person when interacting with Rietveld. - -# Please keep the list sorted. - -Aaron Jacobs -Alex Reece -David Symonds -Ryan Barrett diff --git a/vendor/github.com/golang/mock/mockgen/generic_notgo118.go b/vendor/github.com/golang/mock/mockgen/generic_notgo118.go deleted file mode 100644 index 8fe48c175eb..00000000000 --- a/vendor/github.com/golang/mock/mockgen/generic_notgo118.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !go1.18 -// +build !go1.18 - -package main - -import ( - "go/ast" - - "github.com/golang/mock/mockgen/model" -) - -func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { - return nil -} - -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { - return nil, nil -} - -func getIdentTypeParams(decl interface{}) string { - return "" -} diff --git a/vendor/github.com/golang/mock/mockgen/reflect.go b/vendor/github.com/golang/mock/mockgen/reflect.go deleted file mode 100644 index 4f86a15115e..00000000000 --- a/vendor/github.com/golang/mock/mockgen/reflect.go +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 2012 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -// This file contains the model construction by reflection. - -import ( - "bytes" - "encoding/gob" - "flag" - "fmt" - "go/build" - "io" - "io/ioutil" - "log" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "text/template" - - "github.com/golang/mock/mockgen/model" -) - -var ( - progOnly = flag.Bool("prog_only", false, "(reflect mode) Only generate the reflection program; write it to stdout and exit.") - execOnly = flag.String("exec_only", "", "(reflect mode) If set, execute this reflection program.") - buildFlags = flag.String("build_flags", "", "(reflect mode) Additional flags for go build.") -) - -// reflectMode generates mocks via reflection on an interface. -func reflectMode(importPath string, symbols []string) (*model.Package, error) { - if *execOnly != "" { - return run(*execOnly) - } - - program, err := writeProgram(importPath, symbols) - if err != nil { - return nil, err - } - - if *progOnly { - if _, err := os.Stdout.Write(program); err != nil { - return nil, err - } - os.Exit(0) - } - - wd, _ := os.Getwd() - - // Try to run the reflection program in the current working directory. - if p, err := runInDir(program, wd); err == nil { - return p, nil - } - - // Try to run the program in the same directory as the input package. - if p, err := build.Import(importPath, wd, build.FindOnly); err == nil { - dir := p.Dir - if p, err := runInDir(program, dir); err == nil { - return p, nil - } - } - - // Try to run it in a standard temp directory. - return runInDir(program, "") -} - -func writeProgram(importPath string, symbols []string) ([]byte, error) { - var program bytes.Buffer - data := reflectData{ - ImportPath: importPath, - Symbols: symbols, - } - if err := reflectProgram.Execute(&program, &data); err != nil { - return nil, err - } - return program.Bytes(), nil -} - -// run the given program and parse the output as a model.Package. -func run(program string) (*model.Package, error) { - f, err := ioutil.TempFile("", "") - if err != nil { - return nil, err - } - - filename := f.Name() - defer os.Remove(filename) - if err := f.Close(); err != nil { - return nil, err - } - - // Run the program. - cmd := exec.Command(program, "-output", filename) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - return nil, err - } - - f, err = os.Open(filename) - if err != nil { - return nil, err - } - - // Process output. - var pkg model.Package - if err := gob.NewDecoder(f).Decode(&pkg); err != nil { - return nil, err - } - - if err := f.Close(); err != nil { - return nil, err - } - - return &pkg, nil -} - -// runInDir writes the given program into the given dir, runs it there, and -// parses the output as a model.Package. -func runInDir(program []byte, dir string) (*model.Package, error) { - // We use TempDir instead of TempFile so we can control the filename. - tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_") - if err != nil { - return nil, err - } - defer func() { - if err := os.RemoveAll(tmpDir); err != nil { - log.Printf("failed to remove temp directory: %s", err) - } - }() - const progSource = "prog.go" - var progBinary = "prog.bin" - if runtime.GOOS == "windows" { - // Windows won't execute a program unless it has a ".exe" suffix. - progBinary += ".exe" - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil { - return nil, err - } - - cmdArgs := []string{} - cmdArgs = append(cmdArgs, "build") - if *buildFlags != "" { - cmdArgs = append(cmdArgs, strings.Split(*buildFlags, " ")...) - } - cmdArgs = append(cmdArgs, "-o", progBinary, progSource) - - // Build the program. - buf := bytes.NewBuffer(nil) - cmd := exec.Command("go", cmdArgs...) - cmd.Dir = tmpDir - cmd.Stdout = os.Stdout - cmd.Stderr = io.MultiWriter(os.Stderr, buf) - if err := cmd.Run(); err != nil { - sErr := buf.String() - if strings.Contains(sErr, `cannot find package "."`) && - strings.Contains(sErr, "github.com/golang/mock/mockgen/model") { - fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://github.com/golang/mock#reflect-vendoring-error.\n") - return nil, err - } - return nil, err - } - - return run(filepath.Join(tmpDir, progBinary)) -} - -type reflectData struct { - ImportPath string - Symbols []string -} - -// This program reflects on an interface value, and prints the -// gob encoding of a model.Package to standard output. -// JSON doesn't work because of the model.Type interface. -var reflectProgram = template.Must(template.New("program").Parse(` -package main - -import ( - "encoding/gob" - "flag" - "fmt" - "os" - "path" - "reflect" - - "github.com/golang/mock/mockgen/model" - - pkg_ {{printf "%q" .ImportPath}} -) - -var output = flag.String("output", "", "The output file name, or empty to use stdout.") - -func main() { - flag.Parse() - - its := []struct{ - sym string - typ reflect.Type - }{ - {{range .Symbols}} - { {{printf "%q" .}}, reflect.TypeOf((*pkg_.{{.}})(nil)).Elem()}, - {{end}} - } - pkg := &model.Package{ - // NOTE: This behaves contrary to documented behaviour if the - // package name is not the final component of the import path. - // The reflect package doesn't expose the package name, though. - Name: path.Base({{printf "%q" .ImportPath}}), - } - - for _, it := range its { - intf, err := model.InterfaceFromInterfaceType(it.typ) - if err != nil { - fmt.Fprintf(os.Stderr, "Reflection: %v\n", err) - os.Exit(1) - } - intf.Name = it.sym - pkg.Interfaces = append(pkg.Interfaces, intf) - } - - outfile := os.Stdout - if len(*output) != 0 { - var err error - outfile, err = os.Create(*output) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to open output file %q", *output) - } - defer func() { - if err := outfile.Close(); err != nil { - fmt.Fprintf(os.Stderr, "failed to close output file %q", *output) - os.Exit(1) - } - }() - } - - if err := gob.NewEncoder(outfile).Encode(pkg); err != nil { - fmt.Fprintf(os.Stderr, "gob encode: %v\n", err) - os.Exit(1) - } -} -`)) diff --git a/vendor/github.com/golang/mock/AUTHORS b/vendor/go.uber.org/mock/AUTHORS similarity index 100% rename from vendor/github.com/golang/mock/AUTHORS rename to vendor/go.uber.org/mock/AUTHORS diff --git a/vendor/github.com/golang/mock/LICENSE b/vendor/go.uber.org/mock/LICENSE similarity index 100% rename from vendor/github.com/golang/mock/LICENSE rename to vendor/go.uber.org/mock/LICENSE diff --git a/vendor/github.com/golang/mock/gomock/call.go b/vendor/go.uber.org/mock/gomock/call.go similarity index 86% rename from vendor/github.com/golang/mock/gomock/call.go rename to vendor/go.uber.org/mock/gomock/call.go index 98881596d13..e1fe222afc8 100644 --- a/vendor/github.com/golang/mock/gomock/call.go +++ b/vendor/go.uber.org/mock/gomock/call.go @@ -25,7 +25,7 @@ import ( type Call struct { t TestHelper // for triggering test failures on invalid call setup - receiver interface{} // the receiver of the method call + receiver any // the receiver of the method call method string // the name of the method methodType reflect.Type // the type of the method args []Matcher // the args @@ -41,12 +41,12 @@ type Call struct { // actions are called when this Call is called. Each action gets the args and // can set the return values by returning a non-nil slice. Actions run in the // order they are created. - actions []func([]interface{}) []interface{} + actions []func([]any) []any } // newCall creates a *Call. It requires the method type in order to support // unexported methods. -func newCall(t TestHelper, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { +func newCall(t TestHelper, receiver any, method string, methodType reflect.Type, args ...any) *Call { t.Helper() // TODO: check arity, types. @@ -67,16 +67,18 @@ func newCall(t TestHelper, receiver interface{}, method string, methodType refle // and this line changes, i.e. this code is wrapped in another anonymous function. // 0 is us, 1 is RecordCallWithMethodType(), 2 is the generated recorder, and 3 is the user's test. origin := callerInfo(3) - actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} { + actions := []func([]any) []any{func([]any) []any { // Synthesize the zero value for each of the return args' types. - rets := make([]interface{}, methodType.NumOut()) + rets := make([]any, methodType.NumOut()) for i := 0; i < methodType.NumOut(); i++ { rets[i] = reflect.Zero(methodType.Out(i)).Interface() } return rets }} - return &Call{t: t, receiver: receiver, method: method, methodType: methodType, - args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} + return &Call{ + t: t, receiver: receiver, method: method, methodType: methodType, + args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions, + } } // AnyTimes allows the expectation to be called 0 or more times @@ -107,13 +109,13 @@ func (c *Call) MaxTimes(n int) *Call { // DoAndReturn declares the action to run when the call is matched. // The return values from this function are returned by the mocked function. -// It takes an interface{} argument to support n-arity functions. +// It takes an any argument to support n-arity functions. // The anonymous function must match the function signature mocked method. -func (c *Call) DoAndReturn(f interface{}) *Call { +func (c *Call) DoAndReturn(f any) *Call { // TODO: Check arity and types here, rather than dying badly elsewhere. v := reflect.ValueOf(f) - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { c.t.Helper() ft := v.Type() if c.methodType.NumIn() != ft.NumIn() { @@ -136,7 +138,7 @@ func (c *Call) DoAndReturn(f interface{}) *Call { } } vRets := v.Call(vArgs) - rets := make([]interface{}, len(vRets)) + rets := make([]any, len(vRets)) for i, ret := range vRets { rets[i] = ret.Interface() } @@ -148,13 +150,13 @@ func (c *Call) DoAndReturn(f interface{}) *Call { // Do declares the action to run when the call is matched. The function's // return values are ignored to retain backward compatibility. To use the // return values call DoAndReturn. -// It takes an interface{} argument to support n-arity functions. +// It takes an any argument to support n-arity functions. // The anonymous function must match the function signature mocked method. -func (c *Call) Do(f interface{}) *Call { +func (c *Call) Do(f any) *Call { // TODO: Check arity and types here, rather than dying badly elsewhere. v := reflect.ValueOf(f) - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { c.t.Helper() ft := v.Type() if c.methodType.NumIn() != ft.NumIn() { @@ -183,7 +185,7 @@ func (c *Call) Do(f interface{}) *Call { } // Return declares the values to be returned by the mocked function call. -func (c *Call) Return(rets ...interface{}) *Call { +func (c *Call) Return(rets ...any) *Call { c.t.Helper() mt := c.methodType @@ -215,7 +217,7 @@ func (c *Call) Return(rets ...interface{}) *Call { } } - c.addAction(func([]interface{}) []interface{} { + c.addAction(func([]any) []any { return rets }) @@ -231,7 +233,7 @@ func (c *Call) Times(n int) *Call { // SetArg declares an action that will set the nth argument's value, // indirected through a pointer. Or, in the case of a slice and map, SetArg // will copy value's elements/key-value pairs into the nth argument. -func (c *Call) SetArg(n int, value interface{}) *Call { +func (c *Call) SetArg(n int, value any) *Call { c.t.Helper() mt := c.methodType @@ -251,18 +253,14 @@ func (c *Call) SetArg(n int, value interface{}) *Call { c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]", n, vt, dt, c.origin) } - case reflect.Interface: - // nothing to do - case reflect.Slice: - // nothing to do - case reflect.Map: + case reflect.Interface, reflect.Slice, reflect.Map: // nothing to do default: c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice non-map type %v [%s]", n, at, c.origin) } - c.addAction(func(args []interface{}) []interface{} { + c.addAction(func(args []any) []any { v := reflect.ValueOf(value) switch reflect.TypeOf(args[n]).Kind() { case reflect.Slice: @@ -323,7 +321,7 @@ func (c *Call) String() string { // Tests if the given call matches the expected call. // If yes, returns nil. If no, returns error with message explaining why it does not match. -func (c *Call) matches(args []interface{}) error { +func (c *Call) matches(args []any) error { if !c.methodType.IsVariadic() { if len(args) != len(c.args) { return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d", @@ -429,26 +427,63 @@ func (c *Call) dropPrereqs() (preReqs []*Call) { return } -func (c *Call) call() []func([]interface{}) []interface{} { +func (c *Call) call() []func([]any) []any { c.numCalls++ return c.actions } // InOrder declares that the given calls should occur in order. -func InOrder(calls ...*Call) { +// It panics if the type of any of the arguments isn't *Call or a generated +// mock with an embedded *Call. +func InOrder(args ...any) { + calls := make([]*Call, 0, len(args)) + for i := 0; i < len(args); i++ { + if call := getCall(args[i]); call != nil { + calls = append(calls, call) + continue + } + panic(fmt.Sprintf( + "invalid argument at position %d of type %T, InOrder expects *gomock.Call or generated mock types with an embedded *gomock.Call", + i, + args[i], + )) + } for i := 1; i < len(calls); i++ { calls[i].After(calls[i-1]) } } -func setSlice(arg interface{}, v reflect.Value) { +// getCall checks if the parameter is a *Call or a generated struct +// that wraps a *Call and returns the *Call pointer - if neither, it returns nil. +func getCall(arg any) *Call { + if call, ok := arg.(*Call); ok { + return call + } + t := reflect.ValueOf(arg) + if t.Kind() != reflect.Ptr && t.Kind() != reflect.Interface { + return nil + } + t = t.Elem() + for i := 0; i < t.NumField(); i++ { + f := t.Field(i) + if !f.CanInterface() { + continue + } + if call, ok := f.Interface().(*Call); ok { + return call + } + } + return nil +} + +func setSlice(arg any, v reflect.Value) { va := reflect.ValueOf(arg) for i := 0; i < v.Len(); i++ { va.Index(i).Set(v.Index(i)) } } -func setMap(arg interface{}, v reflect.Value) { +func setMap(arg any, v reflect.Value) { va := reflect.ValueOf(arg) for _, e := range va.MapKeys() { va.SetMapIndex(e, reflect.Value{}) @@ -458,11 +493,11 @@ func setMap(arg interface{}, v reflect.Value) { } } -func (c *Call) addAction(action func([]interface{}) []interface{}) { +func (c *Call) addAction(action func([]any) []any) { c.actions = append(c.actions, action) } -func formatGottenArg(m Matcher, arg interface{}) string { +func formatGottenArg(m Matcher, arg any) string { got := fmt.Sprintf("%v (%T)", arg, arg) if gs, ok := m.(GotFormatter); ok { got = gs.Got(arg) diff --git a/vendor/github.com/golang/mock/gomock/callset.go b/vendor/go.uber.org/mock/gomock/callset.go similarity index 70% rename from vendor/github.com/golang/mock/gomock/callset.go rename to vendor/go.uber.org/mock/gomock/callset.go index 49dba787a40..f5cc592d6f4 100644 --- a/vendor/github.com/golang/mock/gomock/callset.go +++ b/vendor/go.uber.org/mock/gomock/callset.go @@ -18,40 +18,69 @@ import ( "bytes" "errors" "fmt" + "sync" ) // callSet represents a set of expected calls, indexed by receiver and method // name. type callSet struct { // Calls that are still expected. - expected map[callSetKey][]*Call + expected map[callSetKey][]*Call + expectedMu *sync.Mutex // Calls that have been exhausted. exhausted map[callSetKey][]*Call + // when set to true, existing call expectations are overridden when new call expectations are made + allowOverride bool } // callSetKey is the key in the maps in callSet type callSetKey struct { - receiver interface{} + receiver any fname string } func newCallSet() *callSet { - return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)} + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + } +} + +func newOverridableCallSet() *callSet { + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + allowOverride: true, + } } // Add adds a new expected call. func (cs callSet) Add(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + m := cs.expected if call.exhausted() { m = cs.exhausted } + if cs.allowOverride { + m[key] = make([]*Call, 0) + } + m[key] = append(m[key], call) } // Remove removes an expected call. func (cs callSet) Remove(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + calls := cs.expected[key] for i, c := range calls { if c == call { @@ -64,9 +93,12 @@ func (cs callSet) Remove(call *Call) { } // FindMatch searches for a matching call. Returns error with explanation message if no call matched. -func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) { +func (cs callSet) FindMatch(receiver any, method string, args []any) (*Call, error) { key := callSetKey{receiver, method} + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + // Search through the expected calls. expected := cs.expected[key] var callsErrors bytes.Buffer @@ -101,6 +133,9 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac // Failures returns the calls that are not satisfied. func (cs callSet) Failures() []*Call { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + failures := make([]*Call, 0, len(cs.expected)) for _, calls := range cs.expected { for _, call := range calls { @@ -111,3 +146,19 @@ func (cs callSet) Failures() []*Call { } return failures } + +// Satisfied returns true in case all expected calls in this callSet are satisfied. +func (cs callSet) Satisfied() bool { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + + for _, calls := range cs.expected { + for _, call := range calls { + if !call.satisfied() { + return false + } + } + } + + return true +} diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/go.uber.org/mock/gomock/controller.go similarity index 70% rename from vendor/github.com/golang/mock/gomock/controller.go rename to vendor/go.uber.org/mock/gomock/controller.go index 5e2def135bf..674c3298c40 100644 --- a/vendor/github.com/golang/mock/gomock/controller.go +++ b/vendor/go.uber.org/mock/gomock/controller.go @@ -25,8 +25,8 @@ import ( // A TestReporter is something that can be used to report test failures. It // is satisfied by the standard library's *testing.T. type TestReporter interface { - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) + Errorf(format string, args ...any) + Fatalf(format string, args ...any) } // TestHelper is a TestReporter that has the Helper method. It is satisfied @@ -48,27 +48,23 @@ type cleanuper interface { // A Controller represents the top-level control of a mock ecosystem. It // defines the scope and lifetime of mock objects, as well as their // expectations. It is safe to call Controller's methods from multiple -// goroutines. Each test should create a new Controller and invoke Finish via -// defer. +// goroutines. Each test should create a new Controller. // -// func TestFoo(t *testing.T) { -// ctrl := gomock.NewController(t) -// defer ctrl.Finish() -// // .. -// } +// func TestFoo(t *testing.T) { +// ctrl := gomock.NewController(t) +// // .. +// } // -// func TestBar(t *testing.T) { -// t.Run("Sub-Test-1", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// t.Run("Sub-Test-2", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// }) +// func TestBar(t *testing.T) { +// t.Run("Sub-Test-1", st) { +// ctrl := gomock.NewController(st) +// // .. +// }) +// t.Run("Sub-Test-2", st) { +// ctrl := gomock.NewController(st) +// // .. +// }) +// }) type Controller struct { // T should only be called within a generated mock. It is not intended to // be used in user code and may be changed in future versions. T is the @@ -81,12 +77,11 @@ type Controller struct { finished bool } -// NewController returns a new Controller. It is the preferred way to create a -// Controller. +// NewController returns a new Controller. It is the preferred way to create a Controller. // -// New in go1.14+, if you are passing a *testing.T into this function you no -// longer need to call ctrl.Finish() in your test methods. -func NewController(t TestReporter) *Controller { +// Passing [*testing.T] registers cleanup function to automatically call [Controller.Finish] +// when the test and all its subtests complete. +func NewController(t TestReporter, opts ...ControllerOption) *Controller { h, ok := t.(TestHelper) if !ok { h = &nopTestHelper{t} @@ -95,6 +90,9 @@ func NewController(t TestReporter) *Controller { T: h, expectedCalls: newCallSet(), } + for _, opt := range opts { + opt.apply(ctrl) + } if c, ok := isCleanuper(ctrl.T); ok { c.Cleanup(func() { ctrl.T.Helper() @@ -105,15 +103,33 @@ func NewController(t TestReporter) *Controller { return ctrl } +// ControllerOption configures how a Controller should behave. +type ControllerOption interface { + apply(*Controller) +} + +type overridableExpectationsOption struct{} + +// WithOverridableExpectations allows for overridable call expectations +// i.e., subsequent call expectations override existing call expectations +func WithOverridableExpectations() overridableExpectationsOption { + return overridableExpectationsOption{} +} + +func (o overridableExpectationsOption) apply(ctrl *Controller) { + ctrl.expectedCalls = newOverridableCallSet() +} + type cancelReporter struct { t TestHelper cancel func() } -func (r *cancelReporter) Errorf(format string, args ...interface{}) { +func (r *cancelReporter) Errorf(format string, args ...any) { r.t.Errorf(format, args...) } -func (r *cancelReporter) Fatalf(format string, args ...interface{}) { + +func (r *cancelReporter) Fatalf(format string, args ...any) { defer r.cancel() r.t.Fatalf(format, args...) } @@ -138,17 +154,18 @@ type nopTestHelper struct { t TestReporter } -func (h *nopTestHelper) Errorf(format string, args ...interface{}) { +func (h *nopTestHelper) Errorf(format string, args ...any) { h.t.Errorf(format, args...) } -func (h *nopTestHelper) Fatalf(format string, args ...interface{}) { + +func (h *nopTestHelper) Fatalf(format string, args ...any) { h.t.Fatalf(format, args...) } func (h nopTestHelper) Helper() {} // RecordCall is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call { +func (ctrl *Controller) RecordCall(receiver any, method string, args ...any) *Call { ctrl.T.Helper() recv := reflect.ValueOf(receiver) @@ -162,7 +179,7 @@ func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ... } // RecordCallWithMethodType is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { +func (ctrl *Controller) RecordCallWithMethodType(receiver any, method string, methodType reflect.Type, args ...any) *Call { ctrl.T.Helper() call := newCall(ctrl.T, receiver, method, methodType, args...) @@ -175,11 +192,11 @@ func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method st } // Call is called by a mock. It should not be called by user code. -func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} { +func (ctrl *Controller) Call(receiver any, method string, args ...any) []any { ctrl.T.Helper() // Nest this code so we can use defer to make sure the lock is released. - actions := func() []func([]interface{}) []interface{} { + actions := func() []func([]any) []any { ctrl.T.Helper() ctrl.mu.Lock() defer ctrl.mu.Unlock() @@ -190,12 +207,16 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf // and this line changes, i.e. this code is wrapped in another anonymous function. // 0 is us, 1 is controller.Call(), 2 is the generated mock, and 3 is the user's test. origin := callerInfo(3) - ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err) + stringArgs := make([]string, len(args)) + for i, arg := range args { + stringArgs[i] = getString(arg) + } + ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, stringArgs, origin, err) } // Two things happen here: - // * the matching call no longer needs to check prerequite calls, - // * and the prerequite calls are no longer expected, so remove them. + // * the matching call no longer needs to check prerequisite calls, + // * and the prerequisite calls are no longer expected, so remove them. preReqCalls := expected.dropPrereqs() for _, preReqCall := range preReqCalls { ctrl.expectedCalls.Remove(preReqCall) @@ -208,7 +229,7 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf return actions }() - var rets []interface{} + var rets []any for _, action := range actions { if r := action(args); r != nil { rets = r @@ -218,12 +239,11 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf return rets } -// Finish checks to see if all the methods that were expected to be called -// were called. It should be invoked for each Controller. It is not idempotent -// and therefore can only be invoked once. +// Finish checks to see if all the methods that were expected to be called were called. +// It is not idempotent and therefore can only be invoked once. // -// New in go1.14+, if you are passing a *testing.T into NewController function you no -// longer need to call ctrl.Finish() in your test methods. +// Note: If you pass a *testing.T into [NewController], you no longer +// need to call ctrl.Finish() in your test methods. func (ctrl *Controller) Finish() { // If we're currently panicking, probably because this is a deferred call. // This must be recovered in the deferred function. @@ -231,7 +251,15 @@ func (ctrl *Controller) Finish() { ctrl.finish(false, err) } -func (ctrl *Controller) finish(cleanup bool, panicErr interface{}) { +// Satisfied returns whether all expected calls bound to this Controller have been satisfied. +// Calling Finish is then guaranteed to not fail due to missing calls. +func (ctrl *Controller) Satisfied() bool { + ctrl.mu.Lock() + defer ctrl.mu.Unlock() + return ctrl.expectedCalls.Satisfied() +} + +func (ctrl *Controller) finish(cleanup bool, panicErr any) { ctrl.T.Helper() ctrl.mu.Lock() diff --git a/vendor/github.com/golang/mock/gomock/doc.go b/vendor/go.uber.org/mock/gomock/doc.go similarity index 63% rename from vendor/github.com/golang/mock/gomock/doc.go rename to vendor/go.uber.org/mock/gomock/doc.go index 1706b504858..696dda38820 100644 --- a/vendor/github.com/golang/mock/gomock/doc.go +++ b/vendor/go.uber.org/mock/gomock/doc.go @@ -15,18 +15,19 @@ // Package gomock is a mock framework for Go. // // Standard usage: -// (1) Define an interface that you wish to mock. -// type MyInterface interface { -// SomeMethod(x int64, y string) -// } -// (2) Use mockgen to generate a mock from the interface. -// (3) Use the mock in a test: -// func TestMyThing(t *testing.T) { -// mockCtrl := gomock.NewController(t)// -// mockObj := something.NewMockMyInterface(mockCtrl) -// mockObj.EXPECT().SomeMethod(4, "blah") -// // pass mockObj to a real object and play with it. -// } +// +// (1) Define an interface that you wish to mock. +// type MyInterface interface { +// SomeMethod(x int64, y string) +// } +// (2) Use mockgen to generate a mock from the interface. +// (3) Use the mock in a test: +// func TestMyThing(t *testing.T) { +// mockCtrl := gomock.NewController(t) +// mockObj := something.NewMockMyInterface(mockCtrl) +// mockObj.EXPECT().SomeMethod(4, "blah") +// // pass mockObj to a real object and play with it. +// } // // By default, expected calls are not enforced to run in any particular order. // Call order dependency can be enforced by use of InOrder and/or Call.After. @@ -37,17 +38,17 @@ // // Example of using Call.After to chain expected call order: // -// firstCall := mockObj.EXPECT().SomeMethod(1, "first") -// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) -// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) +// firstCall := mockObj.EXPECT().SomeMethod(1, "first") +// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) +// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) // // Example of using InOrder to declare expected call order: // -// gomock.InOrder( -// mockObj.EXPECT().SomeMethod(1, "first"), -// mockObj.EXPECT().SomeMethod(2, "second"), -// mockObj.EXPECT().SomeMethod(3, "third"), -// ) +// gomock.InOrder( +// mockObj.EXPECT().SomeMethod(1, "first"), +// mockObj.EXPECT().SomeMethod(2, "second"), +// mockObj.EXPECT().SomeMethod(3, "third"), +// ) // // The standard TestReporter most users will pass to `NewController` is a // `*testing.T` from the context of the test. Note that this will use the diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/go.uber.org/mock/gomock/matchers.go similarity index 62% rename from vendor/github.com/golang/mock/gomock/matchers.go rename to vendor/go.uber.org/mock/gomock/matchers.go index 2822fb2c8c4..d52495f39e5 100644 --- a/vendor/github.com/golang/mock/gomock/matchers.go +++ b/vendor/go.uber.org/mock/gomock/matchers.go @@ -17,6 +17,7 @@ package gomock import ( "fmt" "reflect" + "regexp" "strings" ) @@ -24,7 +25,7 @@ import ( // It is used to represent the valid or expected arguments to a mocked method. type Matcher interface { // Matches returns whether x is a match. - Matches(x interface{}) bool + Matches(x any) bool // String describes what the matcher matches. String() string @@ -35,7 +36,7 @@ type Matcher interface { // printing . func WantFormatter(s fmt.Stringer, m Matcher) Matcher { type matcher interface { - Matches(x interface{}) bool + Matches(x any) bool } return struct { @@ -63,16 +64,16 @@ func (f StringerFunc) String() string { type GotFormatter interface { // Got is invoked with the received value. The result is used when // printing the failure message. - Got(got interface{}) string + Got(got any) string } // GotFormatterFunc type is an adapter to allow the use of ordinary // functions as a GotFormatter. If f is a function with the appropriate // signature, GotFormatterFunc(f) is a GotFormatter that calls f. -type GotFormatterFunc func(got interface{}) string +type GotFormatterFunc func(got any) string // Got implements GotFormatter. -func (f GotFormatterFunc) Got(got interface{}) string { +func (f GotFormatterFunc) Got(got any) string { return f(got) } @@ -89,7 +90,7 @@ func GotFormatterAdapter(s GotFormatter, m Matcher) Matcher { type anyMatcher struct{} -func (anyMatcher) Matches(interface{}) bool { +func (anyMatcher) Matches(any) bool { return true } @@ -97,11 +98,27 @@ func (anyMatcher) String() string { return "is anything" } +type condMatcher[T any] struct { + fn func(x T) bool +} + +func (c condMatcher[T]) Matches(x any) bool { + typed, ok := x.(T) + if !ok { + return false + } + return c.fn(typed) +} + +func (c condMatcher[T]) String() string { + return "adheres to a custom condition" +} + type eqMatcher struct { - x interface{} + x any } -func (e eqMatcher) Matches(x interface{}) bool { +func (e eqMatcher) Matches(x any) bool { // In case, some value is nil if e.x == nil || x == nil { return reflect.DeepEqual(e.x, x) @@ -120,12 +137,12 @@ func (e eqMatcher) Matches(x interface{}) bool { } func (e eqMatcher) String() string { - return fmt.Sprintf("is equal to %v (%T)", e.x, e.x) + return fmt.Sprintf("is equal to %s (%T)", getString(e.x), e.x) } type nilMatcher struct{} -func (nilMatcher) Matches(x interface{}) bool { +func (nilMatcher) Matches(x any) bool { if x == nil { return true } @@ -148,7 +165,7 @@ type notMatcher struct { m Matcher } -func (n notMatcher) Matches(x interface{}) bool { +func (n notMatcher) Matches(x any) bool { return !n.m.Matches(x) } @@ -156,11 +173,30 @@ func (n notMatcher) String() string { return "not(" + n.m.String() + ")" } +type regexMatcher struct { + regex *regexp.Regexp +} + +func (m regexMatcher) Matches(x any) bool { + switch t := x.(type) { + case string: + return m.regex.MatchString(t) + case []byte: + return m.regex.Match(t) + default: + return false + } +} + +func (m regexMatcher) String() string { + return "matches regex " + m.regex.String() +} + type assignableToTypeOfMatcher struct { targetType reflect.Type } -func (m assignableToTypeOfMatcher) Matches(x interface{}) bool { +func (m assignableToTypeOfMatcher) Matches(x any) bool { return reflect.TypeOf(x).AssignableTo(m.targetType) } @@ -168,11 +204,32 @@ func (m assignableToTypeOfMatcher) String() string { return "is assignable to " + m.targetType.Name() } +type anyOfMatcher struct { + matchers []Matcher +} + +func (am anyOfMatcher) Matches(x any) bool { + for _, m := range am.matchers { + if m.Matches(x) { + return true + } + } + return false +} + +func (am anyOfMatcher) String() string { + ss := make([]string, 0, len(am.matchers)) + for _, matcher := range am.matchers { + ss = append(ss, matcher.String()) + } + return strings.Join(ss, " | ") +} + type allMatcher struct { matchers []Matcher } -func (am allMatcher) Matches(x interface{}) bool { +func (am allMatcher) Matches(x any) bool { for _, m := range am.matchers { if !m.Matches(x) { return false @@ -193,7 +250,7 @@ type lenMatcher struct { i int } -func (m lenMatcher) Matches(x interface{}) bool { +func (m lenMatcher) Matches(x any) bool { v := reflect.ValueOf(x) switch v.Kind() { case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String: @@ -208,10 +265,10 @@ func (m lenMatcher) String() string { } type inAnyOrderMatcher struct { - x interface{} + x any } -func (m inAnyOrderMatcher) Matches(x interface{}) bool { +func (m inAnyOrderMatcher) Matches(x any) bool { given, ok := m.prepareValue(x) if !ok { return false @@ -257,7 +314,7 @@ func (m inAnyOrderMatcher) Matches(x interface{}) bool { return extraInGiven == 0 && missingFromWanted == 0 } -func (m inAnyOrderMatcher) prepareValue(x interface{}) (reflect.Value, bool) { +func (m inAnyOrderMatcher) prepareValue(x any) (reflect.Value, bool) { xValue := reflect.ValueOf(x) switch xValue.Kind() { case reflect.Slice, reflect.Array: @@ -280,12 +337,45 @@ func All(ms ...Matcher) Matcher { return allMatcher{ms} } // Any returns a matcher that always matches. func Any() Matcher { return anyMatcher{} } +// Cond returns a matcher that matches when the given function returns true +// after passing it the parameter to the mock function. +// This is particularly useful in case you want to match over a field of a custom struct, or dynamic logic. +// +// Example usage: +// +// Cond(func(x int){return x == 1}).Matches(1) // returns true +// Cond(func(x int){return x == 2}).Matches(1) // returns false +func Cond[T any](fn func(x T) bool) Matcher { return condMatcher[T]{fn} } + +// AnyOf returns a composite Matcher that returns true if at least one of the +// matchers returns true. +// +// Example usage: +// +// AnyOf(1, 2, 3).Matches(2) // returns true +// AnyOf(1, 2, 3).Matches(10) // returns false +// AnyOf(Nil(), Len(2)).Matches(nil) // returns true +// AnyOf(Nil(), Len(2)).Matches("hi") // returns true +// AnyOf(Nil(), Len(2)).Matches("hello") // returns false +func AnyOf(xs ...any) Matcher { + ms := make([]Matcher, 0, len(xs)) + for _, x := range xs { + if m, ok := x.(Matcher); ok { + ms = append(ms, m) + } else { + ms = append(ms, Eq(x)) + } + } + return anyOfMatcher{ms} +} + // Eq returns a matcher that matches on equality. // // Example usage: -// Eq(5).Matches(5) // returns true -// Eq(5).Matches(4) // returns false -func Eq(x interface{}) Matcher { return eqMatcher{x} } +// +// Eq(5).Matches(5) // returns true +// Eq(5).Matches(4) // returns false +func Eq(x any) Matcher { return eqMatcher{x} } // Len returns a matcher that matches on length. This matcher returns false if // is compared to a type that is not an array, chan, map, slice, or string. @@ -296,35 +386,50 @@ func Len(i int) Matcher { // Nil returns a matcher that matches if the received value is nil. // // Example usage: -// var x *bytes.Buffer -// Nil().Matches(x) // returns true -// x = &bytes.Buffer{} -// Nil().Matches(x) // returns false +// +// var x *bytes.Buffer +// Nil().Matches(x) // returns true +// x = &bytes.Buffer{} +// Nil().Matches(x) // returns false func Nil() Matcher { return nilMatcher{} } // Not reverses the results of its given child matcher. // // Example usage: -// Not(Eq(5)).Matches(4) // returns true -// Not(Eq(5)).Matches(5) // returns false -func Not(x interface{}) Matcher { +// +// Not(Eq(5)).Matches(4) // returns true +// Not(Eq(5)).Matches(5) // returns false +func Not(x any) Matcher { if m, ok := x.(Matcher); ok { return notMatcher{m} } return notMatcher{Eq(x)} } +// Regex checks whether parameter matches the associated regex. +// +// Example usage: +// +// Regex("[0-9]{2}:[0-9]{2}").Matches("23:02") // returns true +// Regex("[0-9]{2}:[0-9]{2}").Matches([]byte{'2', '3', ':', '0', '2'}) // returns true +// Regex("[0-9]{2}:[0-9]{2}").Matches("hello world") // returns false +// Regex("[0-9]{2}").Matches(21) // returns false as it's not a valid type +func Regex(regexStr string) Matcher { + return regexMatcher{regex: regexp.MustCompile(regexStr)} +} + // AssignableToTypeOf is a Matcher that matches if the parameter to the mock // function is assignable to the type of the parameter to this function. // // Example usage: -// var s fmt.Stringer = &bytes.Buffer{} -// AssignableToTypeOf(s).Matches(time.Second) // returns true -// AssignableToTypeOf(s).Matches(99) // returns false // -// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() -// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true -func AssignableToTypeOf(x interface{}) Matcher { +// var s fmt.Stringer = &bytes.Buffer{} +// AssignableToTypeOf(s).Matches(time.Second) // returns true +// AssignableToTypeOf(s).Matches(99) // returns false +// +// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() +// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true +func AssignableToTypeOf(x any) Matcher { if xt, ok := x.(reflect.Type); ok { return assignableToTypeOfMatcher{xt} } @@ -334,8 +439,9 @@ func AssignableToTypeOf(x interface{}) Matcher { // InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order. // // Example usage: -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false -func InAnyOrder(x interface{}) Matcher { +// +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false +func InAnyOrder(x any) Matcher { return inAnyOrderMatcher{x} } diff --git a/vendor/go.uber.org/mock/gomock/string.go b/vendor/go.uber.org/mock/gomock/string.go new file mode 100644 index 00000000000..ec4ca7e4d38 --- /dev/null +++ b/vendor/go.uber.org/mock/gomock/string.go @@ -0,0 +1,36 @@ +package gomock + +import ( + "fmt" + "reflect" +) + +// getString is a safe way to convert a value to a string for printing results +// If the value is a a mock, getString avoids calling the mocked String() method, +// which avoids potential deadlocks +func getString(x any) string { + if isGeneratedMock(x) { + return fmt.Sprintf("%T", x) + } + if s, ok := x.(fmt.Stringer); ok { + return s.String() + } + return fmt.Sprintf("%v", x) +} + +// isGeneratedMock checks if the given type has a "isgomock" field, +// indicating it is a generated mock. +func isGeneratedMock(x any) bool { + typ := reflect.TypeOf(x) + if typ == nil { + return false + } + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + } + if typ.Kind() != reflect.Struct { + return false + } + _, isgomock := typ.FieldByName("isgomock") + return isgomock +} diff --git a/vendor/go.uber.org/mock/mockgen/archive.go b/vendor/go.uber.org/mock/mockgen/archive.go new file mode 100644 index 00000000000..bc80ad119bd --- /dev/null +++ b/vendor/go.uber.org/mock/mockgen/archive.go @@ -0,0 +1,55 @@ +package main + +import ( + "fmt" + "go/token" + "go/types" + "os" + + "go.uber.org/mock/mockgen/model" + + "golang.org/x/tools/go/gcexportdata" +) + +func archiveMode(importPath string, symbols []string, archive string) (*model.Package, error) { + f, err := os.Open(archive) + if err != nil { + return nil, err + } + defer f.Close() + r, err := gcexportdata.NewReader(f) + if err != nil { + return nil, fmt.Errorf("read export data %q: %v", archive, err) + } + + fset := token.NewFileSet() + imports := make(map[string]*types.Package) + tp, err := gcexportdata.Read(r, fset, imports, importPath) + if err != nil { + return nil, err + } + + pkg := &model.Package{ + Name: tp.Name(), + PkgPath: tp.Path(), + Interfaces: make([]*model.Interface, 0, len(symbols)), + } + for _, name := range symbols { + m := tp.Scope().Lookup(name) + tn, ok := m.(*types.TypeName) + if !ok { + continue + } + ti, ok := tn.Type().Underlying().(*types.Interface) + if !ok { + continue + } + it, err := model.InterfaceFromGoTypesType(ti) + if err != nil { + return nil, err + } + it.Name = m.Name() + pkg.Interfaces = append(pkg.Interfaces, it) + } + return pkg, nil +} diff --git a/vendor/go.uber.org/mock/mockgen/deprecated.go b/vendor/go.uber.org/mock/mockgen/deprecated.go new file mode 100644 index 00000000000..0b45a2e3041 --- /dev/null +++ b/vendor/go.uber.org/mock/mockgen/deprecated.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "log" + "os" +) + +const ( + deprecatedFlagProgOnly = "prog_only" + deprecatedFlagExecOnly = "exec_only" +) + +var ( + _ = flag.Bool("prog_only", false, "DEPRECATED (reflect mode) Only generate the reflection program; write it to stdout and exit.") + _ = flag.String("exec_only", "", "DEPRECATED (reflect mode) If set, execute this reflection program.") +) + +// notifyAboutDeprecatedFlags prints a warning message for a deprecated flags if they are set. +func notifyAboutDeprecatedFlags() { + const resetColorPostfix = "\033[0m" + logger := initWarningLogger() + + flag.Visit(func(f *flag.Flag) { + switch f.Name { + case deprecatedFlagProgOnly: + logger.Println("The -prog_only flag is deprecated and has no effect.", resetColorPostfix) + case deprecatedFlagExecOnly: + logger.Println("The -exec_only flag is deprecated and has no effect.", resetColorPostfix) + } + }) +} + +func initWarningLogger() *log.Logger { + const ( + yellowColor = "\033[33m" + warningPrefix = yellowColor + "WARNING: " + ) + + return log.New(os.Stdout, warningPrefix, log.Ldate|log.Ltime) +} diff --git a/vendor/github.com/golang/mock/mockgen/generic_go118.go b/vendor/go.uber.org/mock/mockgen/generic.go similarity index 52% rename from vendor/github.com/golang/mock/mockgen/generic_go118.go rename to vendor/go.uber.org/mock/mockgen/generic.go index b29db9a85c9..c2289c2a884 100644 --- a/vendor/github.com/golang/mock/mockgen/generic_go118.go +++ b/vendor/go.uber.org/mock/mockgen/generic.go @@ -5,16 +5,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build go1.18 -// +build go1.18 - package main import ( + "errors" + "fmt" "go/ast" - "strings" + "go/token" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { @@ -24,7 +23,7 @@ func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { return ts.TypeParams.List } -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.IndexExpr: m, err := p.parseType(pkg, v.X, tps) @@ -64,25 +63,41 @@ func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]b return nil, nil } -func getIdentTypeParams(decl interface{}) string { - if decl == nil { - return "" - } - ts, ok := decl.(*ast.TypeSpec) - if !ok { - return "" - } - if ts.TypeParams == nil || len(ts.TypeParams.List) == 0 { - return "" - } - var sb strings.Builder - sb.WriteString("[") - for i, v := range ts.TypeParams.List { - if i != 0 { - sb.WriteString(", ") +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + var indices []ast.Expr + var typ ast.Expr + switch v := field.Type.(type) { + case *ast.IndexExpr: + indices = []ast.Expr{v.Index} + typ = v.X + case *ast.IndexListExpr: + indices = v.Indices + typ = v.X + case *ast.UnaryExpr: + if v.Op == token.TILDE { + return nil, errConstraintInterface } - sb.WriteString(v.Names[0].Name) + return nil, fmt.Errorf("~T may only appear as constraint for %T", field.Type) + case *ast.BinaryExpr: + if v.Op == token.OR { + return nil, errConstraintInterface + } + return nil, fmt.Errorf("A|B may only appear as constraint for %T", field.Type) + default: + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + } + + nf := &ast.Field{ + Doc: field.Comment, + Names: field.Names, + Type: typ, + Tag: field.Tag, + Comment: field.Comment, } - sb.WriteString("]") - return sb.String() + + it.embeddedInstTypeParams = indices + + return p.parseMethod(nf, it, iface, pkg, tps) } + +var errConstraintInterface = errors.New("interface contains constraints") diff --git a/vendor/go.uber.org/mock/mockgen/gob.go b/vendor/go.uber.org/mock/mockgen/gob.go new file mode 100644 index 00000000000..b5ab0661879 --- /dev/null +++ b/vendor/go.uber.org/mock/mockgen/gob.go @@ -0,0 +1,21 @@ +package main + +import ( + "encoding/gob" + "os" + + "go.uber.org/mock/mockgen/model" +) + +func gobMode(path string) (*model.Package, error) { + in, err := os.Open(path) + if err != nil { + return nil, err + } + defer in.Close() + var pkg model.Package + if err := gob.NewDecoder(in).Decode(&pkg); err != nil { + return nil, err + } + return &pkg, nil +} diff --git a/vendor/github.com/golang/mock/mockgen/mockgen.go b/vendor/go.uber.org/mock/mockgen/mockgen.go similarity index 60% rename from vendor/github.com/golang/mock/mockgen/mockgen.go rename to vendor/go.uber.org/mock/mockgen/mockgen.go index 72a1c96035a..d3d92ba16c9 100644 --- a/vendor/github.com/golang/mock/mockgen/mockgen.go +++ b/vendor/go.uber.org/mock/mockgen/mockgen.go @@ -21,29 +21,30 @@ package main import ( "bytes" "encoding/json" + "errors" "flag" "fmt" "go/token" "io" - "io/ioutil" "log" "os" "os/exec" "path" "path/filepath" + "runtime" "sort" "strconv" "strings" "unicode" - "github.com/golang/mock/mockgen/model" - "golang.org/x/mod/modfile" toolsimports "golang.org/x/tools/imports" + + "go.uber.org/mock/mockgen/model" ) const ( - gomockImportPath = "github.com/golang/mock/gomock" + gomockImportPath = "go.uber.org/mock/gomock" ) var ( @@ -53,22 +54,33 @@ var ( ) var ( - source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.") - destination = flag.String("destination", "", "Output file; defaults to stdout.") - mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.") - packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.") - selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.") - writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") - copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") - - debugParser = flag.Bool("debug_parser", false, "Print out parser results only.") - showVersion = flag.Bool("version", false, "Print version.") + archive = flag.String("archive", "", "(archive mode) Input Go archive file; enables archive mode.") + source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.") + destination = flag.String("destination", "", "Output file; defaults to stdout.") + mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.") + packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.") + selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.") + writeCmdComment = flag.Bool("write_command_comment", true, "Writes the command used as a comment if true.") + writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") + writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (package mode) comment if true.") + writeGenerateDirective = flag.Bool("write_generate_directive", false, "Add //go:generate directive to regenerate the mock") + copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") + buildConstraint = flag.String("build_constraint", "", "If non-empty, added as //go:build ") + typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function") + imports = flag.String("imports", "", "(source mode) Comma-separated name=path pairs of explicit imports to use.") + auxFiles = flag.String("aux_files", "", "(source mode) Comma-separated pkg=path pairs of auxiliary Go source files.") + modelGob = flag.String("model_gob", "", "Skip package/source loading entirely and use the gob encoded model.Package at the given path") + excludeInterfaces = flag.String("exclude_interfaces", "", "Comma-separated names of interfaces to be excluded") + debugParser = flag.Bool("debug_parser", false, "Print out parser results only.") + showVersion = flag.Bool("version", false, "Print version.") ) func main() { flag.Usage = usage flag.Parse() + notifyAboutDeprecatedFlags() + if *showVersion { printVersion() return @@ -77,15 +89,24 @@ func main() { var pkg *model.Package var err error var packageName string - if *source != "" { + + // Switch between modes + switch { + case *modelGob != "": // gob mode + pkg, err = gobMode(*modelGob) + case *source != "": // source mode pkg, err = sourceMode(*source) - } else { - if flag.NArg() != 2 { - usage() - log.Fatal("Expected exactly two arguments") - } + case *archive != "": // archive mode + checkArgs() + packageName = flag.Arg(0) + interfaces := strings.Split(flag.Arg(1), ",") + pkg, err = archiveMode(packageName, interfaces, *archive) + + default: // package mode + checkArgs() packageName = flag.Arg(0) interfaces := strings.Split(flag.Arg(1), ",") + if packageName == "." { dir, err := os.Getwd() if err != nil { @@ -95,9 +116,12 @@ func main() { if err != nil { log.Fatalf("Parse package name failed: %v", err) } + } - pkg, err = reflectMode(packageName, interfaces) + parser := packageModeParser{} + pkg, err = parser.parsePackage(packageName, interfaces) } + if err != nil { log.Fatalf("Loading input failed: %v", err) } @@ -107,22 +131,9 @@ func main() { return } - dst := os.Stdout - if len(*destination) > 0 { - if err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil { - log.Fatalf("Unable to create directory: %v", err) - } - f, err := os.Create(*destination) - if err != nil { - log.Fatalf("Failed opening destination file: %v", err) - } - defer f.Close() - dst = f - } - outputPackageName := *packageOut if outputPackageName == "" { - // pkg.Name in reflect mode is the base name of the import path, + // pkg.Name in package mode is the base name of the import path, // which might have characters that are illegal to have in package names. outputPackageName = "mock_" + sanitize(pkg.Name) } @@ -148,9 +159,13 @@ func main() { } } - g := new(generator) + g := &generator{ + buildConstraint: *buildConstraint, + } if *source != "" { g.filename = *source + } else if *archive != "" { + g.filename = *archive } else { g.srcPackage = packageName g.srcInterfaces = flag.Arg(1) @@ -161,7 +176,7 @@ func main() { g.mockNames = parseMockNames(*mockNames) } if *copyrightFile != "" { - header, err := ioutil.ReadFile(*copyrightFile) + header, err := os.ReadFile(*copyrightFile) if err != nil { log.Fatalf("Failed reading copyright file: %v", err) } @@ -171,7 +186,27 @@ func main() { if err := g.Generate(pkg, outputPackageName, outputPackagePath); err != nil { log.Fatalf("Failed generating mock: %v", err) } - if _, err := dst.Write(g.Output()); err != nil { + output := g.Output() + dst := os.Stdout + if len(*destination) > 0 { + if err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil { + log.Fatalf("Unable to create directory: %v", err) + } + existing, err := os.ReadFile(*destination) + if err != nil && !errors.Is(err, os.ErrNotExist) { + log.Fatalf("Failed reading pre-exiting destination file: %v", err) + } + if len(existing) == len(output) && bytes.Equal(existing, output) { + return + } + f, err := os.Create(*destination) + if err != nil { + log.Fatalf("Failed opening destination file: %v", err) + } + defer f.Close() + dst = f + } + if _, err := dst.Write(output); err != nil { log.Fatalf("Failed writing to destination: %v", err) } } @@ -188,25 +223,58 @@ func parseMockNames(names string) map[string]string { return mocksMap } +func parseExcludeInterfaces(names string) map[string]struct{} { + splitNames := strings.Split(names, ",") + namesSet := make(map[string]struct{}, len(splitNames)) + for _, name := range splitNames { + if name == "" { + continue + } + + namesSet[name] = struct{}{} + } + + if len(namesSet) == 0 { + return nil + } + + return namesSet +} + +func checkArgs() { + if flag.NArg() != 2 { + usage() + log.Fatal("Expected exactly two arguments") + } +} + func usage() { _, _ = io.WriteString(os.Stderr, usageText) flag.PrintDefaults() } -const usageText = `mockgen has two modes of operation: source and reflect. +const usageText = `mockgen has three modes of operation: archive, source and package. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that -may be useful in this mode are -imports and -aux_files. +may be useful in this mode are -imports, -aux_files and -exclude_interfaces. Example: mockgen -source=foo.go [other options] -Reflect mode generates mock interfaces by building a program -that uses reflection to understand interfaces. It is enabled -by passing two non-flag arguments: an import path, and a +Package mode works by specifying the package and interface names. +It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. +You can use "." to refer to the current path's package. Example: mockgen database/sql/driver Conn,Driver + mockgen . SomeInterface + +Archive mode generates mock interfaces from a package archive +file (.a). It is enabled by using the -archive flag and two +non-flag arguments: an import path, and a comma-separated +list of symbols. +Example: + mockgen -archive=pkg.a database/sql/driver Conn,Driver ` @@ -218,12 +286,13 @@ type generator struct { destination string // may be empty srcPackage, srcInterfaces string // may be empty copyrightHeader string + buildConstraint string // may be empty packageMap map[string]string // map from import path to package name } -func (g *generator) p(format string, args ...interface{}) { - fmt.Fprintf(&g.buf, g.indent+format+"\n", args...) +func (g *generator) p(format string, args ...any) { + _, _ = fmt.Fprintf(&g.buf, g.indent+format+"\n", args...) } func (g *generator) in() { @@ -273,13 +342,32 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac g.p("") } + if g.buildConstraint != "" { + g.p("//go:build %s", g.buildConstraint) + // https://pkg.go.dev/cmd/go#hdr-Build_constraints:~:text=a%20build%20constraint%20should%20be%20followed%20by%20a%20blank%20line + g.p("") + } + g.p("// Code generated by MockGen. DO NOT EDIT.") - if g.filename != "" { - g.p("// Source: %v", g.filename) - } else { - g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) + if *writeSourceComment { + if g.filename != "" { + g.p("// Source: %v", g.filename) + } else { + g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) + } + } + if *writeCmdComment { + g.p("//") + g.p("// Generated by this command:") + g.p("//") + // only log the name of the executable, not the full path + name := filepath.Base(os.Args[0]) + if runtime.GOOS == "windows" { + name = strings.TrimSuffix(name, ".exe") + } + g.p("//\t%v", strings.Join(append([]string{name}, os.Args[1:]...), " ")) + g.p("//") } - g.p("") // Get all required imports, and generate unique names for them all. im := pkg.Imports() @@ -305,6 +393,16 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac packagesName := createPackageMap(sortedPaths) + definedImports := make(map[string]string, len(im)) + if *imports != "" { + for _, kv := range strings.Split(*imports, ",") { + eq := strings.Index(kv, "=") + if k, v := kv[:eq], kv[eq+1:]; k != "." { + definedImports[v] = k + } + } + } + g.packageMap = make(map[string]string, len(im)) localNames := make(map[string]bool, len(im)) for _, pth := range sortedPaths { @@ -316,11 +414,16 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac // Local names for an imported package can usually be the basename of the import path. // A couple of situations don't permit that, such as duplicate local names // (e.g. importing "html/template" and "text/template"), or where the basename is - // a keyword (e.g. "foo/case"). + // a keyword (e.g. "foo/case") or when defining a name for that by using the -imports flag. // try base0, base1, ... pkgName := base + + if _, ok := definedImports[pth]; ok { + pkgName = definedImports[pth] + } + i := 0 - for localNames[pkgName] || token.Lookup(pkgName).IsKeyword() { + for localNames[pkgName] || token.Lookup(pkgName).IsKeyword() || pkgName == "any" { pkgName = base + strconv.Itoa(i) i++ } @@ -334,6 +437,12 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac localNames[pkgName] = true } + // Ensure there is an empty line between “generated by” block and + // package documentation comments to follow the recommendations: + // https://go.dev/wiki/CodeReviewComments#package-comments + // That is, “generated by” should not be a package comment. + g.p("") + if *writePkgComment { g.p("// Package %v is a generated GoMock package.", outputPkgName) } @@ -353,6 +462,10 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac g.out() g.p(")") + if *writeGenerateDirective { + g.p("//go:generate %v", strings.Join(os.Args, " ")) + } + for _, intf := range pkg.Interfaces { if err := g.GenerateMockInterface(intf, outputPackagePath); err != nil { return err @@ -406,6 +519,7 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa g.in() g.p("ctrl *gomock.Controller") g.p("recorder *%vMockRecorder%v", mockType, shortTp) + g.p("isgomock struct{}") g.out() g.p("}") g.p("") @@ -436,7 +550,7 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa g.out() g.p("}") - g.GenerateMockMethods(mockType, intf, outputPackagePath, shortTp) + g.GenerateMockMethods(mockType, intf, outputPackagePath, longTp, shortTp, *typed) return nil } @@ -447,13 +561,17 @@ func (b byMethodName) Len() int { return len(b) } func (b byMethodName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b byMethodName) Less(i, j int) bool { return b[i].Name < b[j].Name } -func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride, shortTp string) { +func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride, longTp, shortTp string, typed bool) { sort.Sort(byMethodName(intf.Methods)) for _, m := range intf.Methods { g.p("") _ = g.GenerateMockMethod(mockType, m, pkgOverride, shortTp) g.p("") - _ = g.GenerateMockRecorderMethod(mockType, m, shortTp) + _ = g.GenerateMockRecorderMethod(intf, m, shortTp, typed) + if typed { + g.p("") + _ = g.GenerateMockReturnCallMethod(intf, m, pkgOverride, longTp, shortTp) + } } } @@ -473,8 +591,8 @@ func makeArgString(argNames, argTypes []string) string { // GenerateMockMethod generates a mock method implementation. // If non-empty, pkgOverride is the package in which unqualified types reside. func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride, shortTp string) error { - argNames := g.getArgNames(m) - argTypes := g.getArgTypes(m, pkgOverride) + argNames := g.getArgNames(m, true /* in */) + argTypes := g.getArgTypes(m, pkgOverride, true /* in */) argString := makeArgString(argNames, argTypes) rets := make([]string, len(m.Out)) @@ -503,11 +621,11 @@ func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOver callArgs = ", " + strings.Join(argNames, ", ") } } else { - // Non-trivial. The generated code must build a []interface{}, + // Non-trivial. The generated code must build a []any, // but the variadic argument may be any type. idVarArgs := ia.allocateIdentifier("varargs") idVArg := ia.allocateIdentifier("a") - g.p("%s := []interface{}{%s}", idVarArgs, strings.Join(argNames[:len(argNames)-1], ", ")) + g.p("%s := []any{%s}", idVarArgs, strings.Join(argNames[:len(argNames)-1], ", ")) g.p("for _, %s := range %s {", idVArg, argNames[len(argNames)-1]) g.in() g.p("%s = append(%s, %s)", idVarArgs, idVarArgs, idVArg) @@ -537,8 +655,9 @@ func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOver return nil } -func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, shortTp string) error { - argNames := g.getArgNames(m) +func (g *generator) GenerateMockRecorderMethod(intf *model.Interface, m *model.Method, shortTp string, typed bool) error { + mockType := g.mockName(intf.Name) + argNames := g.getArgNames(m, true) var argString string if m.Variadic == nil { @@ -547,21 +666,26 @@ func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, argString = strings.Join(argNames[:len(argNames)-1], ", ") } if argString != "" { - argString += " interface{}" + argString += " any" } if m.Variadic != nil { if argString != "" { argString += ", " } - argString += fmt.Sprintf("%s ...interface{}", argNames[len(argNames)-1]) + argString += fmt.Sprintf("%s ...any", argNames[len(argNames)-1]) } ia := newIdentifierAllocator(argNames) idRecv := ia.allocateIdentifier("mr") g.p("// %v indicates an expected call of %v.", m.Name, m.Name) - g.p("func (%s *%vMockRecorder%v) %v(%v) *gomock.Call {", idRecv, mockType, shortTp, m.Name, argString) + if typed { + g.p("func (%s *%vMockRecorder%v) %v(%v) *%s%sCall%s {", idRecv, mockType, shortTp, m.Name, argString, mockType, m.Name, shortTp) + } else { + g.p("func (%s *%vMockRecorder%v) %v(%v) *gomock.Call {", idRecv, mockType, shortTp, m.Name, argString) + } + g.in() g.p("%s.mock.ctrl.T.Helper()", idRecv) @@ -577,42 +701,136 @@ func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, } else { // Hard: create a temporary slice. idVarArgs := ia.allocateIdentifier("varargs") - g.p("%s := append([]interface{}{%s}, %s...)", + g.p("%s := append([]any{%s}, %s...)", idVarArgs, strings.Join(argNames[:len(argNames)-1], ", "), argNames[len(argNames)-1]) callArgs = ", " + idVarArgs + "..." } } - g.p(`return %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + if typed { + g.p(`call := %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + g.p(`return &%s%sCall%s{Call: call}`, mockType, m.Name, shortTp) + } else { + g.p(`return %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + } g.out() g.p("}") return nil } -func (g *generator) getArgNames(m *model.Method) []string { - argNames := make([]string, len(m.In)) - for i, p := range m.In { +func (g *generator) GenerateMockReturnCallMethod(intf *model.Interface, m *model.Method, pkgOverride, longTp, shortTp string) error { + mockType := g.mockName(intf.Name) + argNames := g.getArgNames(m, true /* in */) + retNames := g.getArgNames(m, false /* out */) + argTypes := g.getArgTypes(m, pkgOverride, true /* in */) + retTypes := g.getArgTypes(m, pkgOverride, false /* out */) + argString := strings.Join(argTypes, ", ") + + rets := make([]string, len(m.Out)) + for i, p := range m.Out { + rets[i] = p.Type.String(g.packageMap, pkgOverride) + } + + var retString string + switch { + case len(rets) == 1: + retString = " " + rets[0] + case len(rets) > 1: + retString = " (" + strings.Join(rets, ", ") + ")" + } + + ia := newIdentifierAllocator(argNames) + idRecv := ia.allocateIdentifier("c") + + recvStructName := mockType + m.Name + + g.p("// %s%sCall wrap *gomock.Call", mockType, m.Name) + g.p("type %s%sCall%s struct{", mockType, m.Name, longTp) + g.in() + g.p("*gomock.Call") + g.out() + g.p("}") + + g.p("// Return rewrite *gomock.Call.Return") + g.p("func (%s *%sCall%s) Return(%v) *%sCall%s {", idRecv, recvStructName, shortTp, makeArgString(retNames, retTypes), recvStructName, shortTp) + g.in() + var retArgs string + if len(retNames) > 0 { + retArgs = strings.Join(retNames, ", ") + } + g.p(`%s.Call = %v.Call.Return(%v)`, idRecv, idRecv, retArgs) + g.p("return %s", idRecv) + g.out() + g.p("}") + + g.p("// Do rewrite *gomock.Call.Do") + g.p("func (%s *%sCall%s) Do(f func(%v)%v) *%sCall%s {", idRecv, recvStructName, shortTp, argString, retString, recvStructName, shortTp) + g.in() + g.p(`%s.Call = %v.Call.Do(f)`, idRecv, idRecv) + g.p("return %s", idRecv) + g.out() + g.p("}") + + g.p("// DoAndReturn rewrite *gomock.Call.DoAndReturn") + g.p("func (%s *%sCall%s) DoAndReturn(f func(%v)%v) *%sCall%s {", idRecv, recvStructName, shortTp, argString, retString, recvStructName, shortTp) + g.in() + g.p(`%s.Call = %v.Call.DoAndReturn(f)`, idRecv, idRecv) + g.p("return %s", idRecv) + g.out() + g.p("}") + return nil +} + +// nameExistsAsPackage returns true if the name exists as a package name. +// This is used to avoid name collisions when generating mock method arguments. +func (g *generator) nameExistsAsPackage(name string) bool { + for _, symbolName := range g.packageMap { + if symbolName == name { + return true + } + } + return false +} + +func (g *generator) getArgNames(m *model.Method, in bool) []string { + var params []*model.Parameter + if in { + params = m.In + } else { + params = m.Out + } + argNames := make([]string, len(params)) + + for i, p := range params { name := p.Name - if name == "" || name == "_" { + + if name == "" || name == "_" || g.nameExistsAsPackage(name) { name = fmt.Sprintf("arg%d", i) } argNames[i] = name } - if m.Variadic != nil { + if m.Variadic != nil && in { name := m.Variadic.Name - if name == "" { - name = fmt.Sprintf("arg%d", len(m.In)) + + if name == "" || g.nameExistsAsPackage(name) { + name = fmt.Sprintf("arg%d", len(params)) } argNames = append(argNames, name) } return argNames } -func (g *generator) getArgTypes(m *model.Method, pkgOverride string) []string { - argTypes := make([]string, len(m.In)) - for i, p := range m.In { +func (g *generator) getArgTypes(m *model.Method, pkgOverride string, in bool) []string { + var params []*model.Parameter + if in { + params = m.In + } else { + params = m.Out + } + argTypes := make([]string, len(params)) + for i, p := range params { argTypes[i] = p.Type.String(g.packageMap, pkgOverride) } if m.Variadic != nil { @@ -660,7 +878,7 @@ func createPackageMap(importPaths []string) map[string]string { } pkgMap := make(map[string]string) b := bytes.NewBuffer(nil) - args := []string{"list", "-json"} + args := []string{"list", "-json=ImportPath,Name"} args = append(args, importPaths...) cmd := exec.Command("go", args...) cmd.Stdout = b @@ -696,7 +914,7 @@ func parsePackageImport(srcDir string) (string, error) { if moduleMode != "off" { currentDir := srcDir for { - dat, err := ioutil.ReadFile(filepath.Join(currentDir, "go.mod")) + dat, err := os.ReadFile(filepath.Join(currentDir, "go.mod")) if os.IsNotExist(err) { if currentDir == filepath.Dir(currentDir) { // at the root diff --git a/vendor/github.com/golang/mock/mockgen/model/model.go b/vendor/go.uber.org/mock/mockgen/model/model.go similarity index 94% rename from vendor/github.com/golang/mock/mockgen/model/model.go rename to vendor/go.uber.org/mock/mockgen/model/model.go index 94d7f4ba14d..853dbf2d6b5 100644 --- a/vendor/github.com/golang/mock/mockgen/model/model.go +++ b/vendor/go.uber.org/mock/mockgen/model/model.go @@ -24,7 +24,7 @@ import ( ) // pkgPath is the importable path for package model -const pkgPath = "github.com/golang/mock/mockgen/model" +const pkgPath = "go.uber.org/mock/mockgen/model" // Package is a Go package. It may be a subset. type Package struct { @@ -147,12 +147,14 @@ type Type interface { } func init() { - gob.Register(&ArrayType{}) - gob.Register(&ChanType{}) - gob.Register(&FuncType{}) - gob.Register(&MapType{}) - gob.Register(&NamedType{}) - gob.Register(&PointerType{}) + // Call gob.RegisterName with pkgPath as prefix to avoid conflicting with + // github.com/golang/mock/mockgen/model 's registration. + gob.RegisterName(pkgPath+".ArrayType", &ArrayType{}) + gob.RegisterName(pkgPath+".ChanType", &ChanType{}) + gob.RegisterName(pkgPath+".FuncType", &FuncType{}) + gob.RegisterName(pkgPath+".MapType", &MapType{}) + gob.RegisterName(pkgPath+".NamedType", &NamedType{}) + gob.RegisterName(pkgPath+".PointerType", &PointerType{}) // Call gob.RegisterName to make sure it has the consistent name registered // for both gob decoder and encoder. @@ -160,7 +162,7 @@ func init() { // For a non-pointer type, gob.Register will try to get package full path by // calling rt.PkgPath() for a name to register. If your project has vendor // directory, it is possible that PkgPath will get a path like this: - // ../../../vendor/github.com/golang/mock/mockgen/model + // ../../../vendor/go.uber.org/mock/mockgen/model gob.RegisterName(pkgPath+".PredeclaredType", PredeclaredType("")) } @@ -303,7 +305,7 @@ type PredeclaredType string func (pt PredeclaredType) String(map[string]string, string) string { return string(pt) } func (pt PredeclaredType) addImports(map[string]bool) {} -// TypeParametersType contains type paramters for a NamedType. +// TypeParametersType contains type parameters for a NamedType. type TypeParametersType struct { TypeParameters []Type } @@ -467,7 +469,7 @@ func typeFromType(t reflect.Type) (Type, error) { case reflect.Interface: // Two special interfaces. if t.NumMethod() == 0 { - return PredeclaredType("interface{}"), nil + return PredeclaredType("any"), nil } if t == errorType { return PredeclaredType("error"), nil diff --git a/vendor/go.uber.org/mock/mockgen/model/model_gotypes.go b/vendor/go.uber.org/mock/mockgen/model/model_gotypes.go new file mode 100644 index 00000000000..4596c3d28dc --- /dev/null +++ b/vendor/go.uber.org/mock/mockgen/model/model_gotypes.go @@ -0,0 +1,160 @@ +package model + +import ( + "fmt" + "go/types" +) + +// InterfaceFromGoTypesType returns a pointer to an interface for the +// given interface type loaded from archive. +func InterfaceFromGoTypesType(it *types.Interface) (*Interface, error) { + intf := &Interface{} + + for i := 0; i < it.NumMethods(); i++ { + mt := it.Method(i) + // Skip unexported methods. + if !mt.Exported() { + continue + } + m := &Method{ + Name: mt.Name(), + } + + var err error + m.In, m.Variadic, m.Out, err = funcArgsFromGoTypesType(mt.Type().(*types.Signature)) + if err != nil { + return nil, fmt.Errorf("method %q: %w", mt.Name(), err) + } + + intf.AddMethod(m) + } + + return intf, nil +} + +func funcArgsFromGoTypesType(t *types.Signature) (in []*Parameter, variadic *Parameter, out []*Parameter, err error) { + nin := t.Params().Len() + if t.Variadic() { + nin-- + } + for i := 0; i < nin; i++ { + p, err := parameterFromGoTypesType(t.Params().At(i), false) + if err != nil { + return nil, nil, nil, err + } + in = append(in, p) + } + if t.Variadic() { + p, err := parameterFromGoTypesType(t.Params().At(nin), true) + if err != nil { + return nil, nil, nil, err + } + variadic = p + } + for i := 0; i < t.Results().Len(); i++ { + p, err := parameterFromGoTypesType(t.Results().At(i), false) + if err != nil { + return nil, nil, nil, err + } + out = append(out, p) + } + return +} + +func parameterFromGoTypesType(v *types.Var, variadic bool) (*Parameter, error) { + t := v.Type() + if variadic { + t = t.(*types.Slice).Elem() + } + tt, err := typeFromGoTypesType(t) + if err != nil { + return nil, err + } + return &Parameter{Name: v.Name(), Type: tt}, nil +} + +func typeFromGoTypesType(t types.Type) (Type, error) { + if t, ok := t.(*types.Named); ok { + tn := t.Obj() + if tn.Pkg() == nil { + return PredeclaredType(tn.Name()), nil + } + return &NamedType{ + Package: tn.Pkg().Path(), + Type: tn.Name(), + }, nil + } + + // only unnamed or predeclared types after here + + // Lots of types have element types. Let's do the parsing and error checking for all of them. + var elemType Type + if t, ok := t.(interface{ Elem() types.Type }); ok { + var err error + elemType, err = typeFromGoTypesType(t.Elem()) + if err != nil { + return nil, err + } + } + + switch t := t.(type) { + case *types.Array: + return &ArrayType{ + Len: int(t.Len()), + Type: elemType, + }, nil + case *types.Basic: + return PredeclaredType(t.String()), nil + case *types.Chan: + var dir ChanDir + switch t.Dir() { + case types.RecvOnly: + dir = RecvDir + case types.SendOnly: + dir = SendDir + } + return &ChanType{ + Dir: dir, + Type: elemType, + }, nil + case *types.Signature: + in, variadic, out, err := funcArgsFromGoTypesType(t) + if err != nil { + return nil, err + } + return &FuncType{ + In: in, + Out: out, + Variadic: variadic, + }, nil + case *types.Interface: + if t.NumMethods() == 0 { + return PredeclaredType("interface{}"), nil + } + case *types.Map: + kt, err := typeFromGoTypesType(t.Key()) + if err != nil { + return nil, err + } + return &MapType{ + Key: kt, + Value: elemType, + }, nil + case *types.Pointer: + return &PointerType{ + Type: elemType, + }, nil + case *types.Slice: + return &ArrayType{ + Len: -1, + Type: elemType, + }, nil + case *types.Struct: + if t.NumFields() == 0 { + return PredeclaredType("struct{}"), nil + } + // TODO: UnsafePointer + } + + return nil, fmt.Errorf("can't yet turn %v (%T) into a model.Type", t.String(), t) +} diff --git a/vendor/go.uber.org/mock/mockgen/package_mode.go b/vendor/go.uber.org/mock/mockgen/package_mode.go new file mode 100644 index 00000000000..29fab7f8a51 --- /dev/null +++ b/vendor/go.uber.org/mock/mockgen/package_mode.go @@ -0,0 +1,359 @@ +package main + +import ( + "errors" + "flag" + "fmt" + "go/types" + "strings" + + "go.uber.org/mock/mockgen/model" + "golang.org/x/tools/go/packages" +) + +var ( + buildFlags = flag.String("build_flags", "", "(package mode) Additional flags for go build.") +) + +type packageModeParser struct { + pkgName string +} + +func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (*model.Package, error) { + p.pkgName = packageName + + pkg, err := p.loadPackage(packageName) + if err != nil { + return nil, fmt.Errorf("load package: %w", err) + } + + interfaces, err := p.extractInterfacesFromPackage(pkg, ifaces) + if err != nil { + return nil, fmt.Errorf("extract interfaces from package: %w", err) + } + + return &model.Package{ + Name: pkg.Types.Name(), + PkgPath: packageName, + Interfaces: interfaces, + }, nil +} + +func (p *packageModeParser) loadPackage(packageName string) (*packages.Package, error) { + var buildFlagsSet []string + if *buildFlags != "" { + buildFlagsSet = strings.Split(*buildFlags, " ") + } + + cfg := &packages.Config{ + Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles | packages.LoadSyntax, + BuildFlags: buildFlagsSet, + } + pkgs, err := packages.Load(cfg, packageName) + if err != nil { + return nil, fmt.Errorf("load packages: %w", err) + } + + if len(pkgs) != 1 { + return nil, fmt.Errorf("packages length must be 1: %d", len(pkgs)) + } + + if len(pkgs[0].Errors) > 0 { + errs := make([]error, len(pkgs[0].Errors)) + for i, err := range pkgs[0].Errors { + errs[i] = err + } + + return nil, errors.Join(errs...) + } + + return pkgs[0], nil +} + +func (p *packageModeParser) extractInterfacesFromPackage(pkg *packages.Package, ifaces []string) ([]*model.Interface, error) { + interfaces := make([]*model.Interface, len(ifaces)) + for i, iface := range ifaces { + obj := pkg.Types.Scope().Lookup(iface) + if obj == nil { + return nil, fmt.Errorf("interface %s does not exist", iface) + } + + modelIface, err := p.parseInterface(obj) + if err != nil { + return nil, newParseTypeError("parse interface", obj.Name(), err) + } + + interfaces[i] = modelIface + } + + return interfaces, nil +} + +func (p *packageModeParser) parseInterface(obj types.Object) (*model.Interface, error) { + named, ok := types.Unalias(obj.Type()).(*types.Named) + if !ok { + return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying()) + } + + iface, ok := named.Underlying().(*types.Interface) + if !ok { + return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying()) + } + + if p.isConstraint(iface) { + return nil, fmt.Errorf("interface %s is a constraint", obj.Name()) + } + + methods := make([]*model.Method, iface.NumMethods()) + for i := range iface.NumMethods() { + method := iface.Method(i) + typedMethod, ok := method.Type().(*types.Signature) + if !ok { + return nil, fmt.Errorf("method %s is not a signature", method.Name()) + } + + modelFunc, err := p.parseFunc(typedMethod) + if err != nil { + return nil, newParseTypeError("parse method", typedMethod.String(), err) + } + + methods[i] = &model.Method{ + Name: method.Name(), + In: modelFunc.In, + Out: modelFunc.Out, + Variadic: modelFunc.Variadic, + } + } + + if named.TypeParams() == nil { + return &model.Interface{Name: obj.Name(), Methods: methods}, nil + } + + typeParams := make([]*model.Parameter, named.TypeParams().Len()) + for i := range named.TypeParams().Len() { + param := named.TypeParams().At(i) + typeParam, err := p.parseConstraint(param) + if err != nil { + return nil, newParseTypeError("parse type parameter", param.String(), err) + } + + typeParams[i] = &model.Parameter{Name: param.Obj().Name(), Type: typeParam} + } + + return &model.Interface{Name: obj.Name(), Methods: methods, TypeParams: typeParams}, nil +} + +func (o *packageModeParser) isConstraint(t *types.Interface) bool { + for i := range t.NumEmbeddeds() { + embed := t.EmbeddedType(i) + if _, ok := embed.Underlying().(*types.Interface); !ok { + return true + } + } + + return false +} + +func (p *packageModeParser) parseType(t types.Type) (model.Type, error) { + switch t := t.(type) { + case *types.Array: + elementType, err := p.parseType(t.Elem()) + if err != nil { + return nil, newParseTypeError("parse array type", t.Elem().String(), err) + } + return &model.ArrayType{Len: int(t.Len()), Type: elementType}, nil + case *types.Slice: + elementType, err := p.parseType(t.Elem()) + if err != nil { + return nil, newParseTypeError("parse slice type", t.Elem().String(), err) + } + + return &model.ArrayType{Len: -1, Type: elementType}, nil + case *types.Chan: + var dir model.ChanDir + switch t.Dir() { + case types.RecvOnly: + dir = model.RecvDir + case types.SendOnly: + dir = model.SendDir + } + + chanType, err := p.parseType(t.Elem()) + if err != nil { + return nil, newParseTypeError("parse chan type", t.Elem().String(), err) + } + + return &model.ChanType{Dir: dir, Type: chanType}, nil + case *types.Signature: + sig, err := p.parseFunc(t) + if err != nil { + return nil, newParseTypeError("parse signature", t.String(), err) + } + + return sig, nil + case *types.Named, *types.Alias: + object := t.(interface{ Obj() *types.TypeName }) + name := object.Obj().Name() + var pkg string + if object.Obj().Pkg() != nil { + pkg = object.Obj().Pkg().Path() + } + + // TypeArgs method not available for aliases in go1.22 + genericType, ok := t.(interface{ TypeArgs() *types.TypeList }) + if !ok || genericType.TypeArgs() == nil { + return &model.NamedType{ + Package: pkg, + Type: name, + }, nil + } + + typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, genericType.TypeArgs().Len())} + for i := range genericType.TypeArgs().Len() { + typeParam := genericType.TypeArgs().At(i) + typedParam, err := p.parseType(typeParam) + if err != nil { + return nil, newParseTypeError("parse type parameter", typeParam.String(), err) + } + + typeParams.TypeParameters[i] = typedParam + } + + return &model.NamedType{ + Package: pkg, + Type: name, + TypeParams: typeParams, + }, nil + case *types.Interface: + if t.Empty() { + return model.PredeclaredType("any"), nil + } + + return nil, fmt.Errorf("cannot handle non-empty unnamed interfaces") + case *types.Map: + key, err := p.parseType(t.Key()) + if err != nil { + return nil, newParseTypeError("parse map key", t.Key().String(), err) + } + value, err := p.parseType(t.Elem()) + if err != nil { + return nil, newParseTypeError("parse map value", t.Elem().String(), err) + } + + return &model.MapType{Key: key, Value: value}, nil + case *types.Pointer: + valueType, err := p.parseType(t.Elem()) + if err != nil { + return nil, newParseTypeError("parse pointer type", t.Elem().String(), err) + } + + return &model.PointerType{Type: valueType}, nil + case *types.Struct: + if t.NumFields() > 0 { + return nil, fmt.Errorf("cannot handle non-empty unnamed structs") + } + + return model.PredeclaredType("struct{}"), nil + case *types.Basic: + return model.PredeclaredType(t.Name()), nil + case *types.Tuple: + panic("tuple field") // TODO + case *types.TypeParam: + return &model.NamedType{Type: t.Obj().Name()}, nil + default: + panic("unknown type") // TODO + } +} + +func (p *packageModeParser) parseFunc(sig *types.Signature) (*model.FuncType, error) { + var variadic *model.Parameter + params := make([]*model.Parameter, 0, sig.Params().Len()) + for i := range sig.Params().Len() { + param := sig.Params().At(i) + + isVariadicParam := i == sig.Params().Len()-1 && sig.Variadic() + parseType := param.Type() + if isVariadicParam { + sliceType, ok := param.Type().(*types.Slice) + if !ok { + return nil, newParseTypeError("variadic parameter is not a slice", param.String(), nil) + } + + parseType = sliceType.Elem() + } + + paramType, err := p.parseType(parseType) + if err != nil { + return nil, newParseTypeError("parse parameter type", parseType.String(), err) + } + + modelParameter := &model.Parameter{Type: paramType, Name: param.Name()} + + if isVariadicParam { + variadic = modelParameter + } else { + params = append(params, modelParameter) + } + } + + if len(params) == 0 { + params = nil + } + + results := make([]*model.Parameter, sig.Results().Len()) + for i := range sig.Results().Len() { + result := sig.Results().At(i) + + resultType, err := p.parseType(result.Type()) + if err != nil { + return nil, newParseTypeError("parse result type", result.Type().String(), err) + } + + results[i] = &model.Parameter{Type: resultType, Name: result.Name()} + } + + if len(results) == 0 { + results = nil + } + + return &model.FuncType{ + In: params, + Out: results, + Variadic: variadic, + }, nil +} + +func (p *packageModeParser) parseConstraint(t *types.TypeParam) (model.Type, error) { + if t == nil { + return nil, fmt.Errorf("nil type param") + } + + typeParam, err := p.parseType(t.Constraint()) + if err != nil { + return nil, newParseTypeError("parse constraint type", t.Constraint().String(), err) + } + + return typeParam, nil +} + +type parseTypeError struct { + message string + typeString string + error error +} + +func newParseTypeError(message string, typeString string, error error) *parseTypeError { + return &parseTypeError{typeString: typeString, error: error, message: message} +} + +func (p parseTypeError) Error() string { + if p.error != nil { + return fmt.Sprintf("%s: error parsing %s: %s", p.message, p.typeString, p.error) + } + + return fmt.Sprintf("%s: error parsing type %s", p.message, p.typeString) +} + +func (p parseTypeError) Unwrap() error { + return p.error +} diff --git a/vendor/github.com/golang/mock/mockgen/parse.go b/vendor/go.uber.org/mock/mockgen/parse.go similarity index 84% rename from vendor/github.com/golang/mock/mockgen/parse.go rename to vendor/go.uber.org/mock/mockgen/parse.go index 21c0d70a305..f43321c331b 100644 --- a/vendor/github.com/golang/mock/mockgen/parse.go +++ b/vendor/go.uber.org/mock/mockgen/parse.go @@ -18,7 +18,6 @@ package main import ( "errors" - "flag" "fmt" "go/ast" "go/build" @@ -26,19 +25,14 @@ import ( "go/parser" "go/token" "go/types" - "io/ioutil" "log" + "os" "path" "path/filepath" "strconv" "strings" - "github.com/golang/mock/mockgen/model" -) - -var ( - imports = flag.String("imports", "", "(source mode) Comma-separated name=path pairs of explicit imports to use.") - auxFiles = flag.String("aux_files", "", "(source mode) Comma-separated pkg=path pairs of auxiliary Go source files.") + "go.uber.org/mock/mockgen/model" ) // sourceMode generates mocks via source file. @@ -81,6 +75,10 @@ func sourceMode(source string) (*model.Package, error) { } } + if *excludeInterfaces != "" { + p.excludeNamesSet = parseExcludeInterfaces(*excludeInterfaces) + } + // Handle -aux_files. if err := p.parseAuxFiles(*auxFiles); err != nil { return nil, err @@ -169,12 +167,13 @@ type fileParser struct { auxFiles []*ast.File auxInterfaces *interfaceCache srcDir string + excludeNamesSet map[string]struct{} } -func (p *fileParser) errorf(pos token.Pos, format string, args ...interface{}) error { +func (p *fileParser) errorf(pos token.Pos, format string, args ...any) error { ps := p.fileSet.Position(pos) format = "%s:%d:%d: " + format - args = append([]interface{}{ps.Filename, ps.Line, ps.Column}, args...) + args = append([]any{ps.Filename, ps.Line, ps.Column}, args...) return fmt.Errorf(format, args...) } @@ -229,7 +228,13 @@ func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Packag var is []*model.Interface for ni := range iterInterfaces(file) { + if _, ok := p.excludeNamesSet[ni.name.String()]; ok { + continue + } i, err := p.parseInterface(ni.name.String(), importPath, ni) + if errors.Is(err, errConstraintInterface) { + continue + } if err != nil { return nil, err } @@ -274,20 +279,77 @@ func (p *fileParser) parsePackage(path string) (*fileParser, error) { return newP, nil } +func (p *fileParser) constructInstParams(pkg string, params []*ast.Field, instParams []model.Type, embeddedInstParams []ast.Expr, tps map[string]model.Type) ([]model.Type, error) { + pm := make(map[string]int) + var i int + for _, v := range params { + for _, n := range v.Names { + pm[n.Name] = i + instParams = append(instParams, model.PredeclaredType(n.Name)) + i++ + } + } + + var runtimeInstParams []model.Type + for _, instParam := range embeddedInstParams { + switch t := instParam.(type) { + case *ast.Ident: + if idx, ok := pm[t.Name]; ok { + runtimeInstParams = append(runtimeInstParams, instParams[idx]) + continue + } + } + modelType, err := p.parseType(pkg, instParam, tps) + if err != nil { + return nil, err + } + runtimeInstParams = append(runtimeInstParams, modelType) + } + + return runtimeInstParams, nil +} + +func (p *fileParser) constructTps(it *namedInterface) (tps map[string]model.Type) { + tps = make(map[string]model.Type) + n := 0 + for _, tp := range it.typeParams { + for _, tm := range tp.Names { + tps[tm.Name] = nil + if len(it.instTypes) != 0 { + tps[tm.Name] = it.instTypes[n] + n++ + } + } + } + return tps +} + +// parseInterface loads interface specified by pkg and name, parses it and returns +// a new model with the parsed. func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*model.Interface, error) { iface := &model.Interface{Name: name} - tps := make(map[string]bool) - + tps := p.constructTps(it) tp, err := p.parseFieldList(pkg, it.typeParams, tps) if err != nil { return nil, fmt.Errorf("unable to parse interface type parameters: %v", name) } + iface.TypeParams = tp - for _, v := range tp { - tps[v.Name] = true + for _, field := range it.it.Methods.List { + var methods []*model.Method + if methods, err = p.parseMethod(field, it, iface, pkg, tps); err != nil { + return nil, err + } + for _, m := range methods { + iface.AddMethod(m) + } } + return iface, nil +} - for _, field := range it.it.Methods.List { +func (p *fileParser) parseMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + // {} for git diff + { switch v := field.Type.(type) { case *ast.FuncType: if nn := len(field.Names); nn != 1 { @@ -301,7 +363,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if err != nil { return nil, err } - iface.AddMethod(m) + return []*model.Method{m}, nil case *ast.Ident: // Embedded interface in this package. embeddedIfaceType := p.auxInterfaces.Get(pkg, v.String()) @@ -312,10 +374,15 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var embeddedIface *model.Interface if embeddedIfaceType != nil { var err error + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } + } else { // This is built-in error interface. if v.String() == model.ErrorInterface.Name { @@ -330,16 +397,17 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", pkg, v.String()) } + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = ip.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } } } - // Copy the methods. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil case *ast.SelectorExpr: // Embedded interface in another package. filePkg, sel := v.X.(*ast.Ident).String(), v.Sel.String() @@ -352,6 +420,10 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var err error embeddedIfaceType := p.auxInterfaces.Get(filePkg, sel) if embeddedIfaceType != nil { + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(sel, filePkg, embeddedIfaceType) if err != nil { return nil, err @@ -373,24 +445,25 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if embeddedIfaceType = parser.importedInterfaces.Get(path, sel); embeddedIfaceType == nil { return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", path, sel) } + + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = parser.parseInterface(sel, path, embeddedIfaceType) if err != nil { return nil, err } } - // Copy the methods. // TODO: apply shadowing rules. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil default: - return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + return p.parseGenericMethod(field, it, iface, pkg, tps) } } - return iface, nil } -func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { +func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]model.Type) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { if f.Params != nil { regParams := f.Params.List if isVariadic(f) { @@ -417,7 +490,7 @@ func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) return } -func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]bool) ([]*model.Parameter, error) { +func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]model.Type) ([]*model.Parameter, error) { nf := 0 for _, f := range fields { nn := len(f.Names) @@ -451,7 +524,7 @@ func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[str return ps, nil } -func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.ArrayType: ln := -1 @@ -493,7 +566,8 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m } return &model.FuncType{In: in, Out: out, Variadic: variadic}, nil case *ast.Ident: - if v.IsExported() && !tps[v.Name] { + it, ok := tps[v.Name] + if v.IsExported() && !ok { // `pkg` may be an aliased imported pkg // if so, patch the import w/ the fully qualified import maybeImportedPkg, ok := p.imports[pkg] @@ -503,14 +577,16 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m // assume type in this package return &model.NamedType{Package: pkg, Type: v.Name}, nil } - + if ok && it != nil { + return it, nil + } // assume predeclared type return model.PredeclaredType(v.Name), nil case *ast.InterfaceType: if v.Methods != nil && len(v.Methods.List) > 0 { return nil, p.errorf(v.Pos(), "can't handle non-empty unnamed interface types") } - return model.PredeclaredType("interface{}"), nil + return model.PredeclaredType("any"), nil case *ast.MapType: key, err := p.parseType(pkg, v.Key, tps) if err != nil { @@ -657,9 +733,11 @@ func importsOfFile(file *ast.File) (normalImports map[string]importedPackage, do } type namedInterface struct { - name *ast.Ident - it *ast.InterfaceType - typeParams []*ast.Field + name *ast.Ident + it *ast.InterfaceType + typeParams []*ast.Field + embeddedInstTypeParams []ast.Expr + instTypes []model.Type } // Create an iterator over all interfaces in file. @@ -681,7 +759,7 @@ func iterInterfaces(file *ast.File) <-chan *namedInterface { continue } - ch <- &namedInterface{ts.Name, it, getTypeSpecTypeParams(ts)} + ch <- &namedInterface{name: ts.Name, it: it, typeParams: getTypeSpecTypeParams(ts)} } } close(ch) @@ -701,7 +779,7 @@ func isVariadic(f *ast.FuncType) bool { // packageNameOfDir get package import path via dir func packageNameOfDir(srcDir string) (string, error) { - files, err := ioutil.ReadDir(srcDir) + files, err := os.ReadDir(srcDir) if err != nil { log.Fatal(err) } diff --git a/vendor/github.com/golang/mock/mockgen/version.go b/vendor/go.uber.org/mock/mockgen/version.go similarity index 100% rename from vendor/github.com/golang/mock/mockgen/version.go rename to vendor/go.uber.org/mock/mockgen/version.go diff --git a/vendor/modules.txt b/vendor/modules.txt index 130f74acf30..054d3332300 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -962,11 +962,6 @@ github.com/golang-jwt/jwt/v4 # github.com/golang-jwt/jwt/v5 v5.2.2 ## explicit; go 1.18 github.com/golang-jwt/jwt/v5 -# github.com/golang/mock v1.7.0-rc.1 -## explicit; go 1.15 -github.com/golang/mock/gomock -github.com/golang/mock/mockgen -github.com/golang/mock/mockgen/model # github.com/golang/protobuf v1.5.4 ## explicit; go 1.17 github.com/golang/protobuf/proto @@ -2423,6 +2418,11 @@ go.opentelemetry.io/proto/otlp/trace/v1 go.uber.org/automaxprocs/internal/cgroups go.uber.org/automaxprocs/internal/runtime go.uber.org/automaxprocs/maxprocs +# go.uber.org/mock v0.6.0 +## explicit; go 1.23.0 +go.uber.org/mock/gomock +go.uber.org/mock/mockgen +go.uber.org/mock/mockgen/model # go.uber.org/multierr v1.11.0 ## explicit; go 1.19 go.uber.org/multierr