From feeb42826313dbc2f6bd6b9c84f24b86f33da7d4 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 21 Nov 2024 17:44:45 +0800 Subject: [PATCH] add go.uber.org/mock to tools.go, generate mocks using go run --- go.mod | 4 ++- go.sum | 7 +++- .../internal/mock/key_vault_client.go | 32 +++++++++++-------- kms/azurekms/key_vault_test.go | 4 +-- kms/azurekms/signer_test.go | 2 +- tools.go | 7 ++++ 6 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 tools.go diff --git a/go.mod b/go.mod index 4ceba470..c801437f 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/kms v1.37.5 github.com/go-jose/go-jose/v3 v3.0.3 github.com/go-piv/piv-go/v2 v2.3.0 - github.com/golang/mock v1.6.0 github.com/google/go-tpm v0.9.1 github.com/google/go-tpm-tools v0.4.4 github.com/googleapis/gax-go/v2 v2.13.0 @@ -24,6 +23,7 @@ require ( github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262 github.com/smallstep/go-attestation v0.4.4-0.20240109183208-413678f90935 github.com/stretchr/testify v1.9.0 + go.uber.org/mock v0.5.0 golang.org/x/crypto v0.28.0 golang.org/x/net v0.30.0 golang.org/x/sys v0.27.0 @@ -86,10 +86,12 @@ require ( go.opentelemetry.io/otel v1.29.0 // indirect go.opentelemetry.io/otel/metric v1.29.0 // indirect go.opentelemetry.io/otel/trace v1.29.0 // indirect + golang.org/x/mod v0.18.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/text v0.19.0 // indirect golang.org/x/time v0.7.0 // indirect + golang.org/x/tools v0.22.0 // indirect google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect diff --git a/go.sum b/go.sum index 09266652..5f6e862d 100644 --- a/go.sum +++ b/go.sum @@ -349,7 +349,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -893,6 +892,8 @@ go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= @@ -962,6 +963,8 @@ 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.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1239,6 +1242,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= +golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/kms/azurekms/internal/mock/key_vault_client.go b/kms/azurekms/internal/mock/key_vault_client.go index 6b351ec1..39080be9 100644 --- a/kms/azurekms/internal/mock/key_vault_client.go +++ b/kms/azurekms/internal/mock/key_vault_client.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: go.step.sm/crypto/kms/azurekms (interfaces: KeyVaultClient) +// +// Generated by this command: +// +// mockgen -package mock -mock_names=KeyVaultClient=KeyVaultClient -destination internal/mock/key_vault_client.go go.step.sm/crypto/kms/azurekms KeyVaultClient +// // Package mock is a generated GoMock package. package mock @@ -9,13 +14,14 @@ import ( reflect "reflect" azkeys "github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // KeyVaultClient is a mock of KeyVaultClient interface. type KeyVaultClient struct { ctrl *gomock.Controller recorder *KeyVaultClientMockRecorder + isgomock struct{} } // KeyVaultClientMockRecorder is the mock recorder for KeyVaultClient. @@ -36,46 +42,46 @@ func (m *KeyVaultClient) EXPECT() *KeyVaultClientMockRecorder { } // CreateKey mocks base method. -func (m *KeyVaultClient) CreateKey(arg0 context.Context, arg1 string, arg2 azkeys.CreateKeyParameters, arg3 *azkeys.CreateKeyOptions) (azkeys.CreateKeyResponse, error) { +func (m *KeyVaultClient) CreateKey(ctx context.Context, name string, parameters azkeys.CreateKeyParameters, options *azkeys.CreateKeyOptions) (azkeys.CreateKeyResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateKey", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "CreateKey", ctx, name, parameters, options) ret0, _ := ret[0].(azkeys.CreateKeyResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // CreateKey indicates an expected call of CreateKey. -func (mr *KeyVaultClientMockRecorder) CreateKey(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *KeyVaultClientMockRecorder) CreateKey(ctx, name, parameters, options any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateKey", reflect.TypeOf((*KeyVaultClient)(nil).CreateKey), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateKey", reflect.TypeOf((*KeyVaultClient)(nil).CreateKey), ctx, name, parameters, options) } // GetKey mocks base method. -func (m *KeyVaultClient) GetKey(arg0 context.Context, arg1, arg2 string, arg3 *azkeys.GetKeyOptions) (azkeys.GetKeyResponse, error) { +func (m *KeyVaultClient) GetKey(ctx context.Context, name, version string, options *azkeys.GetKeyOptions) (azkeys.GetKeyResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetKey", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "GetKey", ctx, name, version, options) ret0, _ := ret[0].(azkeys.GetKeyResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // GetKey indicates an expected call of GetKey. -func (mr *KeyVaultClientMockRecorder) GetKey(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *KeyVaultClientMockRecorder) GetKey(ctx, name, version, options any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKey", reflect.TypeOf((*KeyVaultClient)(nil).GetKey), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKey", reflect.TypeOf((*KeyVaultClient)(nil).GetKey), ctx, name, version, options) } // Sign mocks base method. -func (m *KeyVaultClient) Sign(arg0 context.Context, arg1, arg2 string, arg3 azkeys.SignParameters, arg4 *azkeys.SignOptions) (azkeys.SignResponse, error) { +func (m *KeyVaultClient) Sign(ctx context.Context, name, version string, parameters azkeys.SignParameters, options *azkeys.SignOptions) (azkeys.SignResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Sign", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "Sign", ctx, name, version, parameters, options) ret0, _ := ret[0].(azkeys.SignResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // Sign indicates an expected call of Sign. -func (mr *KeyVaultClientMockRecorder) Sign(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *KeyVaultClientMockRecorder) Sign(ctx, name, version, parameters, options any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*KeyVaultClient)(nil).Sign), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*KeyVaultClient)(nil).Sign), ctx, name, version, parameters, options) } diff --git a/kms/azurekms/key_vault_test.go b/kms/azurekms/key_vault_test.go index 7cb22934..651e366e 100644 --- a/kms/azurekms/key_vault_test.go +++ b/kms/azurekms/key_vault_test.go @@ -1,4 +1,4 @@ -//go:generate mockgen -package mock -mock_names=KeyVaultClient=KeyVaultClient -destination internal/mock/key_vault_client.go go.step.sm/crypto/kms/azurekms KeyVaultClient +//go:generate go run go.uber.org/mock/mockgen -package mock -mock_names=KeyVaultClient=KeyVaultClient -destination internal/mock/key_vault_client.go go.step.sm/crypto/kms/azurekms KeyVaultClient package azurekms import ( @@ -15,10 +15,10 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys" "github.com/go-jose/go-jose/v3" - "github.com/golang/mock/gomock" "go.step.sm/crypto/keyutil" "go.step.sm/crypto/kms/apiv1" "go.step.sm/crypto/kms/azurekms/internal/mock" + "go.uber.org/mock/gomock" ) var errTest = fmt.Errorf("test error") diff --git a/kms/azurekms/signer_test.go b/kms/azurekms/signer_test.go index 693a474b..f940828d 100644 --- a/kms/azurekms/signer_test.go +++ b/kms/azurekms/signer_test.go @@ -12,9 +12,9 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys" - "github.com/golang/mock/gomock" "go.step.sm/crypto/keyutil" "go.step.sm/crypto/kms/apiv1" + "go.uber.org/mock/gomock" "golang.org/x/crypto/cryptobyte" "golang.org/x/crypto/cryptobyte/asn1" ) diff --git a/tools.go b/tools.go new file mode 100644 index 00000000..d423fcd3 --- /dev/null +++ b/tools.go @@ -0,0 +1,7 @@ +//go:build tools + +package crypto + +import ( + _ "go.uber.org/mock/mockgen" +)