diff --git a/go.mod b/go.mod index 2af9f4383a..f8c83e9682 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/vishvananda/netns v0.0.4 go.etcd.io/bbolt v1.3.7 go.opencensus.io v0.24.0 - go.uber.org/mock v0.2.0 + go.uber.org/mock v0.3.0 golang.org/x/sync v0.3.0 golang.org/x/sys v0.10.0 google.golang.org/grpc v1.57.0 @@ -87,7 +87,7 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/yashtewari/glob-intersection v0.1.0 // indirect golang.org/x/crypto v0.9.0 // indirect - golang.org/x/mod v0.10.0 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.8.0 // indirect diff --git a/go.sum b/go.sum index 7854d83878..cdf06c3633 100644 --- a/go.sum +++ b/go.sum @@ -1097,8 +1097,8 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= -go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM= +go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= +go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -1164,8 +1164,8 @@ 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.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 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= diff --git a/internal/computeagent/mock/computeagent_mock.pb.go b/internal/computeagent/mock/computeagent_mock.pb.go index 5a5310cef8..5acd1f69e4 100644 --- a/internal/computeagent/mock/computeagent_mock.pb.go +++ b/internal/computeagent/mock/computeagent_mock.pb.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: computeagent_ttrpc.pb.go - +// +// Generated by this command: +// +// mockgen.exe -source=computeagent_ttrpc.pb.go -package=computeagent_mock -destination=mock\computeagent_mock.pb.go +// // Package computeagent_mock is a generated GoMock package. package computeagent_mock @@ -45,7 +49,7 @@ func (m *MockComputeAgentService) AddNIC(arg0 context.Context, arg1 *computeagen } // AddNIC indicates an expected call of AddNIC. -func (mr *MockComputeAgentServiceMockRecorder) AddNIC(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockComputeAgentServiceMockRecorder) AddNIC(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNIC", reflect.TypeOf((*MockComputeAgentService)(nil).AddNIC), arg0, arg1) } @@ -60,7 +64,7 @@ func (m *MockComputeAgentService) AssignPCI(arg0 context.Context, arg1 *computea } // AssignPCI indicates an expected call of AssignPCI. -func (mr *MockComputeAgentServiceMockRecorder) AssignPCI(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockComputeAgentServiceMockRecorder) AssignPCI(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AssignPCI", reflect.TypeOf((*MockComputeAgentService)(nil).AssignPCI), arg0, arg1) } @@ -75,7 +79,7 @@ func (m *MockComputeAgentService) DeleteNIC(arg0 context.Context, arg1 *computea } // DeleteNIC indicates an expected call of DeleteNIC. -func (mr *MockComputeAgentServiceMockRecorder) DeleteNIC(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockComputeAgentServiceMockRecorder) DeleteNIC(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteNIC", reflect.TypeOf((*MockComputeAgentService)(nil).DeleteNIC), arg0, arg1) } @@ -90,7 +94,7 @@ func (m *MockComputeAgentService) ModifyNIC(arg0 context.Context, arg1 *computea } // ModifyNIC indicates an expected call of ModifyNIC. -func (mr *MockComputeAgentServiceMockRecorder) ModifyNIC(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockComputeAgentServiceMockRecorder) ModifyNIC(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModifyNIC", reflect.TypeOf((*MockComputeAgentService)(nil).ModifyNIC), arg0, arg1) } @@ -105,7 +109,7 @@ func (m *MockComputeAgentService) RemovePCI(arg0 context.Context, arg1 *computea } // RemovePCI indicates an expected call of RemovePCI. -func (mr *MockComputeAgentServiceMockRecorder) RemovePCI(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockComputeAgentServiceMockRecorder) RemovePCI(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemovePCI", reflect.TypeOf((*MockComputeAgentService)(nil).RemovePCI), arg0, arg1) } diff --git a/pkg/ncproxy/nodenetsvc/v0/mock/nodenetsvc_mock.pb.go b/pkg/ncproxy/nodenetsvc/v0/mock/nodenetsvc_mock.pb.go index 2ced336e97..122fac6e58 100644 --- a/pkg/ncproxy/nodenetsvc/v0/mock/nodenetsvc_mock.pb.go +++ b/pkg/ncproxy/nodenetsvc/v0/mock/nodenetsvc_mock.pb.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: nodenetsvc_grpc.pb.go - +// +// Generated by this command: +// +// mockgen.exe -source=nodenetsvc_grpc.pb.go -package=nodenetsvc_v0_mock -destination=mock\nodenetsvc_mock.pb.go +// // Package nodenetsvc_v0_mock is a generated GoMock package. package nodenetsvc_v0_mock @@ -39,7 +43,7 @@ func (m *MockNodeNetworkServiceClient) EXPECT() *MockNodeNetworkServiceClientMoc // ConfigureContainerNetworking mocks base method. func (m *MockNodeNetworkServiceClient) ConfigureContainerNetworking(ctx context.Context, in *v0.ConfigureContainerNetworkingRequest, opts ...grpc.CallOption) (*v0.ConfigureContainerNetworkingResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -50,16 +54,16 @@ func (m *MockNodeNetworkServiceClient) ConfigureContainerNetworking(ctx context. } // ConfigureContainerNetworking indicates an expected call of ConfigureContainerNetworking. -func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureContainerNetworking(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureContainerNetworking(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureContainerNetworking", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).ConfigureContainerNetworking), varargs...) } // ConfigureNetworking mocks base method. func (m *MockNodeNetworkServiceClient) ConfigureNetworking(ctx context.Context, in *v0.ConfigureNetworkingRequest, opts ...grpc.CallOption) (*v0.ConfigureNetworkingResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -70,16 +74,16 @@ func (m *MockNodeNetworkServiceClient) ConfigureNetworking(ctx context.Context, } // ConfigureNetworking indicates an expected call of ConfigureNetworking. -func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureNetworking(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureNetworking(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).ConfigureNetworking), varargs...) } // GetHostLocalIpAddress mocks base method. func (m *MockNodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context, in *v0.GetHostLocalIpAddressRequest, opts ...grpc.CallOption) (*v0.GetHostLocalIpAddressResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -90,16 +94,16 @@ func (m *MockNodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context } // GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. -func (mr *MockNodeNetworkServiceClientMockRecorder) GetHostLocalIpAddress(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) GetHostLocalIpAddress(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).GetHostLocalIpAddress), varargs...) } // PingNodeNetworkService mocks base method. func (m *MockNodeNetworkServiceClient) PingNodeNetworkService(ctx context.Context, in *v0.PingNodeNetworkServiceRequest, opts ...grpc.CallOption) (*v0.PingNodeNetworkServiceResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -110,9 +114,9 @@ func (m *MockNodeNetworkServiceClient) PingNodeNetworkService(ctx context.Contex } // PingNodeNetworkService indicates an expected call of PingNodeNetworkService. -func (mr *MockNodeNetworkServiceClientMockRecorder) PingNodeNetworkService(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) PingNodeNetworkService(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PingNodeNetworkService", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).PingNodeNetworkService), varargs...) } @@ -149,7 +153,7 @@ func (m *MockNodeNetworkServiceServer) ConfigureContainerNetworking(arg0 context } // ConfigureContainerNetworking indicates an expected call of ConfigureContainerNetworking. -func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureContainerNetworking(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureContainerNetworking(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureContainerNetworking", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).ConfigureContainerNetworking), arg0, arg1) } @@ -164,7 +168,7 @@ func (m *MockNodeNetworkServiceServer) ConfigureNetworking(arg0 context.Context, } // ConfigureNetworking indicates an expected call of ConfigureNetworking. -func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureNetworking(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureNetworking(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).ConfigureNetworking), arg0, arg1) } @@ -179,7 +183,7 @@ func (m *MockNodeNetworkServiceServer) GetHostLocalIpAddress(arg0 context.Contex } // GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. -func (mr *MockNodeNetworkServiceServerMockRecorder) GetHostLocalIpAddress(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) GetHostLocalIpAddress(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).GetHostLocalIpAddress), arg0, arg1) } @@ -194,7 +198,7 @@ func (m *MockNodeNetworkServiceServer) PingNodeNetworkService(arg0 context.Conte } // PingNodeNetworkService indicates an expected call of PingNodeNetworkService. -func (mr *MockNodeNetworkServiceServerMockRecorder) PingNodeNetworkService(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) PingNodeNetworkService(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PingNodeNetworkService", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).PingNodeNetworkService), arg0, arg1) } diff --git a/pkg/ncproxy/nodenetsvc/v1/mock/nodenetsvc_mock.pb.go b/pkg/ncproxy/nodenetsvc/v1/mock/nodenetsvc_mock.pb.go index 21d0bc3956..93b5aa9965 100644 --- a/pkg/ncproxy/nodenetsvc/v1/mock/nodenetsvc_mock.pb.go +++ b/pkg/ncproxy/nodenetsvc/v1/mock/nodenetsvc_mock.pb.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: nodenetsvc_grpc.pb.go - +// +// Generated by this command: +// +// mockgen.exe -source=nodenetsvc_grpc.pb.go -package=nodenetsvc_v1_mock -destination=mock\nodenetsvc_mock.pb.go +// // Package nodenetsvc_v1_mock is a generated GoMock package. package nodenetsvc_v1_mock @@ -39,7 +43,7 @@ func (m *MockNodeNetworkServiceClient) EXPECT() *MockNodeNetworkServiceClientMoc // ConfigureContainerNetworking mocks base method. func (m *MockNodeNetworkServiceClient) ConfigureContainerNetworking(ctx context.Context, in *v1.ConfigureContainerNetworkingRequest, opts ...grpc.CallOption) (*v1.ConfigureContainerNetworkingResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -50,16 +54,16 @@ func (m *MockNodeNetworkServiceClient) ConfigureContainerNetworking(ctx context. } // ConfigureContainerNetworking indicates an expected call of ConfigureContainerNetworking. -func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureContainerNetworking(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureContainerNetworking(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureContainerNetworking", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).ConfigureContainerNetworking), varargs...) } // ConfigureNetworking mocks base method. func (m *MockNodeNetworkServiceClient) ConfigureNetworking(ctx context.Context, in *v1.ConfigureNetworkingRequest, opts ...grpc.CallOption) (*v1.ConfigureNetworkingResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -70,16 +74,16 @@ func (m *MockNodeNetworkServiceClient) ConfigureNetworking(ctx context.Context, } // ConfigureNetworking indicates an expected call of ConfigureNetworking. -func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureNetworking(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) ConfigureNetworking(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).ConfigureNetworking), varargs...) } // GetHostLocalIpAddress mocks base method. func (m *MockNodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context, in *v1.GetHostLocalIpAddressRequest, opts ...grpc.CallOption) (*v1.GetHostLocalIpAddressResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -90,16 +94,16 @@ func (m *MockNodeNetworkServiceClient) GetHostLocalIpAddress(ctx context.Context } // GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. -func (mr *MockNodeNetworkServiceClientMockRecorder) GetHostLocalIpAddress(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) GetHostLocalIpAddress(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).GetHostLocalIpAddress), varargs...) } // PingNodeNetworkService mocks base method. func (m *MockNodeNetworkServiceClient) PingNodeNetworkService(ctx context.Context, in *v1.PingNodeNetworkServiceRequest, opts ...grpc.CallOption) (*v1.PingNodeNetworkServiceResponse, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, in} + varargs := []any{ctx, in} for _, a := range opts { varargs = append(varargs, a) } @@ -110,9 +114,9 @@ func (m *MockNodeNetworkServiceClient) PingNodeNetworkService(ctx context.Contex } // PingNodeNetworkService indicates an expected call of PingNodeNetworkService. -func (mr *MockNodeNetworkServiceClientMockRecorder) PingNodeNetworkService(ctx, in interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceClientMockRecorder) PingNodeNetworkService(ctx, in any, opts ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, in}, opts...) + varargs := append([]any{ctx, in}, opts...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PingNodeNetworkService", reflect.TypeOf((*MockNodeNetworkServiceClient)(nil).PingNodeNetworkService), varargs...) } @@ -149,7 +153,7 @@ func (m *MockNodeNetworkServiceServer) ConfigureContainerNetworking(arg0 context } // ConfigureContainerNetworking indicates an expected call of ConfigureContainerNetworking. -func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureContainerNetworking(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureContainerNetworking(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureContainerNetworking", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).ConfigureContainerNetworking), arg0, arg1) } @@ -164,7 +168,7 @@ func (m *MockNodeNetworkServiceServer) ConfigureNetworking(arg0 context.Context, } // ConfigureNetworking indicates an expected call of ConfigureNetworking. -func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureNetworking(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) ConfigureNetworking(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureNetworking", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).ConfigureNetworking), arg0, arg1) } @@ -179,7 +183,7 @@ func (m *MockNodeNetworkServiceServer) GetHostLocalIpAddress(arg0 context.Contex } // GetHostLocalIpAddress indicates an expected call of GetHostLocalIpAddress. -func (mr *MockNodeNetworkServiceServerMockRecorder) GetHostLocalIpAddress(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) GetHostLocalIpAddress(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostLocalIpAddress", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).GetHostLocalIpAddress), arg0, arg1) } @@ -194,7 +198,7 @@ func (m *MockNodeNetworkServiceServer) PingNodeNetworkService(arg0 context.Conte } // PingNodeNetworkService indicates an expected call of PingNodeNetworkService. -func (mr *MockNodeNetworkServiceServerMockRecorder) PingNodeNetworkService(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNodeNetworkServiceServerMockRecorder) PingNodeNetworkService(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PingNodeNetworkService", reflect.TypeOf((*MockNodeNetworkServiceServer)(nil).PingNodeNetworkService), arg0, arg1) } diff --git a/test/go.mod b/test/go.mod index 635791352c..aa3d01b87f 100644 --- a/test/go.mod +++ b/test/go.mod @@ -99,7 +99,7 @@ require ( go.opentelemetry.io/otel v1.14.0 // indirect go.opentelemetry.io/otel/trace v1.14.0 // indirect golang.org/x/crypto v0.9.0 // indirect - golang.org/x/mod v0.10.0 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.9.1 // indirect diff --git a/test/go.sum b/test/go.sum index 34eac0b2e2..d0ea8728f4 100644 --- a/test/go.sum +++ b/test/go.sum @@ -1860,7 +1860,7 @@ go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66 go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= -go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM= +go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -1957,8 +1957,9 @@ golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 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= @@ -2341,7 +2342,6 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= 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.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.9/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= diff --git a/vendor/go.uber.org/mock/gomock/call.go b/vendor/go.uber.org/mock/gomock/call.go index 98881596d1..e1ea826377 100644 --- a/vendor/go.uber.org/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,9 +67,9 @@ 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() } @@ -107,13 +107,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 +136,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 +148,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 +183,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 +215,7 @@ func (c *Call) Return(rets ...interface{}) *Call { } } - c.addAction(func([]interface{}) []interface{} { + c.addAction(func([]any) []any { return rets }) @@ -231,7 +231,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 @@ -262,7 +262,7 @@ func (c *Call) SetArg(n int, value interface{}) *Call { 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 +323,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 +429,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 +495,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/go.uber.org/mock/gomock/callset.go b/vendor/go.uber.org/mock/gomock/callset.go index f2131a14e7..f5cc592d6f 100644 --- a/vendor/go.uber.org/mock/gomock/callset.go +++ b/vendor/go.uber.org/mock/gomock/callset.go @@ -35,7 +35,7 @@ type callSet struct { // callSetKey is the key in the maps in callSet type callSetKey struct { - receiver interface{} + receiver any fname string } @@ -50,7 +50,7 @@ func newCallSet() *callSet { func newOverridableCallSet() *callSet { return &callSet{ expected: make(map[callSetKey][]*Call), - expectedMu: &sync.Mutex{}, + expectedMu: &sync.Mutex{}, exhausted: make(map[callSetKey][]*Call), allowOverride: true, } @@ -93,7 +93,7 @@ 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() diff --git a/vendor/go.uber.org/mock/gomock/controller.go b/vendor/go.uber.org/mock/gomock/controller.go index de904c8c9f..6846d0d053 100644 --- a/vendor/go.uber.org/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 @@ -53,19 +53,16 @@ type cleanuper interface { // // func TestFoo(t *testing.T) { // ctrl := gomock.NewController(t) -// defer ctrl.Finish() // // .. // } // // 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() // // .. // }) // }) @@ -81,11 +78,10 @@ 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. +// 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 { @@ -130,10 +126,10 @@ type cancelReporter struct { 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...) } @@ -158,17 +154,17 @@ 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) @@ -182,7 +178,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...) @@ -195,11 +191,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() @@ -228,7 +224,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 @@ -238,12 +234,8 @@ 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. -// -// 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. +// 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. func (ctrl *Controller) Finish() { // If we're currently panicking, probably because this is a deferred call. // This must be recovered in the deferred function. @@ -257,7 +249,7 @@ func (ctrl *Controller) Satisfied() bool { return ctrl.expectedCalls.Satisfied() } -func (ctrl *Controller) finish(cleanup bool, panicErr interface{}) { +func (ctrl *Controller) finish(cleanup bool, panicErr any) { ctrl.T.Helper() ctrl.mu.Lock() diff --git a/vendor/go.uber.org/mock/gomock/doc.go b/vendor/go.uber.org/mock/gomock/doc.go index f1a304fb3c..696dda3882 100644 --- a/vendor/go.uber.org/mock/gomock/doc.go +++ b/vendor/go.uber.org/mock/gomock/doc.go @@ -23,7 +23,7 @@ // (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)// +// mockCtrl := gomock.NewController(t) // mockObj := something.NewMockMyInterface(mockCtrl) // mockObj.EXPECT().SomeMethod(4, "blah") // // pass mockObj to a real object and play with it. diff --git a/vendor/go.uber.org/mock/gomock/matchers.go b/vendor/go.uber.org/mock/gomock/matchers.go index 6d5eff4fe4..bac4623b1f 100644 --- a/vendor/go.uber.org/mock/gomock/matchers.go +++ b/vendor/go.uber.org/mock/gomock/matchers.go @@ -24,7 +24,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 +35,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 +63,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 +89,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 +97,23 @@ func (anyMatcher) String() string { return "is anything" } +type condMatcher struct { + fn func(x any) bool +} + +func (c condMatcher) Matches(x any) bool { + return c.fn(x) +} + +func (condMatcher) 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) @@ -125,7 +137,7 @@ func (e eqMatcher) String() string { type nilMatcher struct{} -func (nilMatcher) Matches(x interface{}) bool { +func (nilMatcher) Matches(x any) bool { if x == nil { return true } @@ -148,7 +160,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) } @@ -160,7 +172,7 @@ 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) } @@ -172,7 +184,7 @@ 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 +205,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 +220,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 +269,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,13 +292,23 @@ 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 any){return x.(int) == 1}).Matches(1) // returns true +// Cond(func(x any){return x.(int) == 2}).Matches(1) // returns false +func Cond(fn func(x any) bool) Matcher { return condMatcher{fn} } + // 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} } +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. @@ -310,7 +332,7 @@ func Nil() Matcher { return nilMatcher{} } // // Not(Eq(5)).Matches(4) // returns true // Not(Eq(5)).Matches(5) // returns false -func Not(x interface{}) Matcher { +func Not(x any) Matcher { if m, ok := x.(Matcher); ok { return notMatcher{m} } @@ -328,7 +350,7 @@ func Not(x interface{}) Matcher { // // var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() // AssignableToTypeOf(ctx).Matches(context.Background()) // returns true -func AssignableToTypeOf(x interface{}) Matcher { +func AssignableToTypeOf(x any) Matcher { if xt, ok := x.(reflect.Type); ok { return assignableToTypeOfMatcher{xt} } @@ -341,6 +363,6 @@ func AssignableToTypeOf(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 interface{}) Matcher { +func InAnyOrder(x any) Matcher { return inAnyOrderMatcher{x} } diff --git a/vendor/go.uber.org/mock/mockgen/generic_go118.go b/vendor/go.uber.org/mock/mockgen/generic_go118.go index 917a15e855..635402dc50 100644 --- a/vendor/go.uber.org/mock/mockgen/generic_go118.go +++ b/vendor/go.uber.org/mock/mockgen/generic_go118.go @@ -11,6 +11,7 @@ package main import ( + "fmt" "go/ast" "strings" @@ -24,7 +25,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,7 +65,7 @@ func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]b return nil, nil } -func getIdentTypeParams(decl interface{}) string { +func getIdentTypeParams(decl any) string { if decl == nil { return "" } @@ -86,3 +87,30 @@ func getIdentTypeParams(decl interface{}) string { sb.WriteString("]") return sb.String() } + +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 + 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, + } + + it.embeddedInstTypeParams = indices + + return p.parseMethod(nf, it, iface, pkg, tps) +} diff --git a/vendor/go.uber.org/mock/mockgen/generic_notgo118.go b/vendor/go.uber.org/mock/mockgen/generic_notgo118.go index b608438ca4..8a779c8b2d 100644 --- a/vendor/go.uber.org/mock/mockgen/generic_notgo118.go +++ b/vendor/go.uber.org/mock/mockgen/generic_notgo118.go @@ -18,6 +18,7 @@ package main import ( + "fmt" "go/ast" "go.uber.org/mock/mockgen/model" @@ -27,10 +28,14 @@ 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) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { return nil, nil } -func getIdentTypeParams(decl interface{}) string { +func getIdentTypeParams(decl any) string { return "" } + +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) +} diff --git a/vendor/go.uber.org/mock/mockgen/mockgen.go b/vendor/go.uber.org/mock/mockgen/mockgen.go index 12b0191491..feb747fac5 100644 --- a/vendor/go.uber.org/mock/mockgen/mockgen.go +++ b/vendor/go.uber.org/mock/mockgen/mockgen.go @@ -26,7 +26,6 @@ import ( "fmt" "go/token" "io" - "io/ioutil" "log" "os" "os/exec" @@ -37,10 +36,10 @@ import ( "strings" "unicode" - "go.uber.org/mock/mockgen/model" - "golang.org/x/mod/modfile" toolsimports "golang.org/x/tools/imports" + + "go.uber.org/mock/mockgen/model" ) const ( @@ -54,14 +53,19 @@ 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") - typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function") + 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.") + writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect 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") + 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.") + 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.") @@ -150,7 +154,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) } @@ -166,11 +170,11 @@ func main() { if err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil { log.Fatalf("Unable to create directory: %v", err) } - existing, err := ioutil.ReadFile(*destination) + 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.Compare(existing, output) == 0 { + if len(existing) == len(output) && bytes.Equal(existing, output) { return } f, err := os.Create(*destination) @@ -197,6 +201,24 @@ 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 usage() { _, _ = io.WriteString(os.Stderr, usageText) flag.PrintDefaults() @@ -231,7 +253,7 @@ type generator struct { packageMap map[string]string // map from import path to package name } -func (g *generator) p(format string, args ...interface{}) { +func (g *generator) p(format string, args ...any) { fmt.Fprintf(&g.buf, g.indent+format+"\n", args...) } @@ -283,12 +305,17 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac } 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) + } } - g.p("") + g.p("//") + g.p("// Generated by this command:") + // only log the name of the executable, not the full path + g.p("// %v", strings.Join(append([]string{filepath.Base(os.Args[0])}, os.Args[1:]...), " ")) // Get all required imports, and generate unique names for them all. im := pkg.Imports() @@ -314,6 +341,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 { @@ -325,9 +362,14 @@ 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[base]; ok { + pkgName = definedImports[base] + } + i := 0 for localNames[pkgName] || token.Lookup(pkgName).IsKeyword() { pkgName = base + strconv.Itoa(i) @@ -362,6 +404,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 @@ -516,11 +562,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) @@ -560,14 +606,14 @@ func (g *generator) GenerateMockRecorderMethod(intf *model.Interface, mockType s 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) @@ -595,7 +641,7 @@ func (g *generator) GenerateMockRecorderMethod(intf *model.Interface, mockType s } 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]) @@ -793,7 +839,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/go.uber.org/mock/mockgen/model/model.go b/vendor/go.uber.org/mock/mockgen/model/model.go index 70c52feb02..e2dde53853 100644 --- a/vendor/go.uber.org/mock/mockgen/model/model.go +++ b/vendor/go.uber.org/mock/mockgen/model/model.go @@ -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. @@ -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/parse.go b/vendor/go.uber.org/mock/mockgen/parse.go index aab9066062..9521409986 100644 --- a/vendor/go.uber.org/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,8 +25,8 @@ import ( "go/parser" "go/token" "go/types" - "io/ioutil" "log" + "os" "path" "path/filepath" "strconv" @@ -36,11 +35,6 @@ import ( "go.uber.org/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.") -) - // sourceMode generates mocks via source file. func sourceMode(source string) (*model.Package, error) { srcDir, err := filepath.Abs(filepath.Dir(source)) @@ -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,6 +228,9 @@ 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 err != nil { return nil, err @@ -274,20 +276,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 +360,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 +371,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 +394,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 +417,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 +442,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 +487,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 +521,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 +563,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 +574,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 +730,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 +756,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 +776,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/go.uber.org/mock/mockgen/reflect.go b/vendor/go.uber.org/mock/mockgen/reflect.go index bcb1319d4e..8f519f6a5d 100644 --- a/vendor/go.uber.org/mock/mockgen/reflect.go +++ b/vendor/go.uber.org/mock/mockgen/reflect.go @@ -23,7 +23,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "log" "os" "os/exec" @@ -92,7 +91,7 @@ func writeProgram(importPath string, symbols []string) ([]byte, error) { // run the given program and parse the output as a model.Package. func run(program string) (*model.Package, error) { - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") if err != nil { return nil, err } @@ -133,7 +132,7 @@ func run(program string) (*model.Package, error) { // 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_") + tmpDir, err := os.MkdirTemp(dir, "gomock_reflect_") if err != nil { return nil, err } @@ -149,7 +148,7 @@ func runInDir(program []byte, dir string) (*model.Package, error) { progBinary += ".exe" } - if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil { return nil, err } diff --git a/vendor/golang.org/x/mod/modfile/print.go b/vendor/golang.org/x/mod/modfile/print.go index 524f93022a..2a0123d4b9 100644 --- a/vendor/golang.org/x/mod/modfile/print.go +++ b/vendor/golang.org/x/mod/modfile/print.go @@ -16,7 +16,13 @@ import ( func Format(f *FileSyntax) []byte { pr := &printer{} pr.file(f) - return pr.Bytes() + + // remove trailing blank lines + b := pr.Bytes() + for len(b) > 0 && b[len(b)-1] == '\n' && (len(b) == 1 || b[len(b)-2] == '\n') { + b = b[:len(b)-1] + } + return b } // A printer collects the state during printing of a file or expression. @@ -59,7 +65,11 @@ func (p *printer) newline() { } p.trim() - p.printf("\n") + if b := p.Bytes(); len(b) == 0 || (len(b) >= 2 && b[len(b)-1] == '\n' && b[len(b)-2] == '\n') { + // skip the blank line at top of file or after a blank line + } else { + p.printf("\n") + } for i := 0; i < p.margin; i++ { p.printf("\t") } diff --git a/vendor/golang.org/x/mod/modfile/rule.go b/vendor/golang.org/x/mod/modfile/rule.go index 6bcde8fabe..b4dd7997b6 100644 --- a/vendor/golang.org/x/mod/modfile/rule.go +++ b/vendor/golang.org/x/mod/modfile/rule.go @@ -35,12 +35,13 @@ import ( // A File is the parsed, interpreted form of a go.mod file. type File struct { - Module *Module - Go *Go - Require []*Require - Exclude []*Exclude - Replace []*Replace - Retract []*Retract + Module *Module + Go *Go + Toolchain *Toolchain + Require []*Require + Exclude []*Exclude + Replace []*Replace + Retract []*Retract Syntax *FileSyntax } @@ -58,6 +59,12 @@ type Go struct { Syntax *Line } +// A Toolchain is the toolchain statement. +type Toolchain struct { + Name string // "go1.21rc1" + Syntax *Line +} + // An Exclude is a single exclude statement. type Exclude struct { Mod module.Version @@ -296,9 +303,13 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse return f, nil } -var GoVersionRE = lazyregexp.New(`^([1-9][0-9]*)\.(0|[1-9][0-9]*)$`) +var GoVersionRE = lazyregexp.New(`^([1-9][0-9]*)\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))?([a-z]+[0-9]+)?$`) var laxGoVersionRE = lazyregexp.New(`^v?(([1-9][0-9]*)\.(0|[1-9][0-9]*))([^0-9].*)$`) +// Toolchains must be named beginning with `go1`, +// like "go1.20.3" or "go1.20.3-gccgo". As a special case, "default" is also permitted. +var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`) + func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) { // If strict is false, this module is a dependency. // We ignore all unknown directives as well as main-module-only @@ -364,6 +375,21 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a f.Go = &Go{Syntax: line} f.Go.Version = args[0] + case "toolchain": + if f.Toolchain != nil { + errorf("repeated toolchain statement") + return + } + if len(args) != 1 { + errorf("toolchain directive expects exactly one argument") + return + } else if strict && !ToolchainRE.MatchString(args[0]) { + errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0]) + return + } + f.Toolchain = &Toolchain{Syntax: line} + f.Toolchain.Name = args[0] + case "module": if f.Module != nil { errorf("repeated module statement") @@ -612,6 +638,22 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string, f.Go = &Go{Syntax: line} f.Go.Version = args[0] + case "toolchain": + if f.Toolchain != nil { + errorf("repeated toolchain statement") + return + } + if len(args) != 1 { + errorf("toolchain directive expects exactly one argument") + return + } else if !ToolchainRE.MatchString(args[0]) { + errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0]) + return + } + + f.Toolchain = &Toolchain{Syntax: line} + f.Toolchain.Name = args[0] + case "use": if len(args) != 1 { errorf("usage: %s local/dir", verb) @@ -926,7 +968,7 @@ func (f *File) Cleanup() { func (f *File) AddGoStmt(version string) error { if !GoVersionRE.MatchString(version) { - return fmt.Errorf("invalid language version string %q", version) + return fmt.Errorf("invalid language version %q", version) } if f.Go == nil { var hint Expr @@ -944,6 +986,44 @@ func (f *File) AddGoStmt(version string) error { return nil } +// DropGoStmt deletes the go statement from the file. +func (f *File) DropGoStmt() { + if f.Go != nil { + f.Go.Syntax.markRemoved() + f.Go = nil + } +} + +// DropToolchainStmt deletes the toolchain statement from the file. +func (f *File) DropToolchainStmt() { + if f.Toolchain != nil { + f.Toolchain.Syntax.markRemoved() + f.Toolchain = nil + } +} + +func (f *File) AddToolchainStmt(name string) error { + if !ToolchainRE.MatchString(name) { + return fmt.Errorf("invalid toolchain name %q", name) + } + if f.Toolchain == nil { + var hint Expr + if f.Go != nil && f.Go.Syntax != nil { + hint = f.Go.Syntax + } else if f.Module != nil && f.Module.Syntax != nil { + hint = f.Module.Syntax + } + f.Toolchain = &Toolchain{ + Name: name, + Syntax: f.Syntax.addLine(hint, "toolchain", name), + } + } else { + f.Toolchain.Name = name + f.Syntax.updateLine(f.Toolchain.Syntax, "toolchain", name) + } + return nil +} + // AddRequire sets the first require line for path to version vers, // preserving any existing comments for that line and removing all // other lines for path. @@ -1387,13 +1467,21 @@ func (f *File) DropRetract(vi VersionInterval) error { func (f *File) SortBlocks() { f.removeDups() // otherwise sorting is unsafe + // semanticSortForExcludeVersionV is the Go version (plus leading "v") at which + // lines in exclude blocks start to use semantic sort instead of lexicographic sort. + // See go.dev/issue/60028. + const semanticSortForExcludeVersionV = "v1.21" + useSemanticSortForExclude := f.Go != nil && semver.Compare("v"+f.Go.Version, semanticSortForExcludeVersionV) >= 0 + for _, stmt := range f.Syntax.Stmt { block, ok := stmt.(*LineBlock) if !ok { continue } less := lineLess - if block.Token[0] == "retract" { + if block.Token[0] == "exclude" && useSemanticSortForExclude { + less = lineExcludeLess + } else if block.Token[0] == "retract" { less = lineRetractLess } sort.SliceStable(block.Line, func(i, j int) bool { @@ -1496,6 +1584,22 @@ func lineLess(li, lj *Line) bool { return len(li.Token) < len(lj.Token) } +// lineExcludeLess reports whether li should be sorted before lj for lines in +// an "exclude" block. +func lineExcludeLess(li, lj *Line) bool { + if len(li.Token) != 2 || len(lj.Token) != 2 { + // Not a known exclude specification. + // Fall back to sorting lexicographically. + return lineLess(li, lj) + } + // An exclude specification has two tokens: ModulePath and Version. + // Compare module path by string order and version by semver rules. + if pi, pj := li.Token[0], lj.Token[0]; pi != pj { + return pi < pj + } + return semver.Compare(li.Token[1], lj.Token[1]) < 0 +} + // lineRetractLess returns whether li should be sorted before lj for lines in // a "retract" block. It treats each line as a version interval. Single versions // are compared as if they were intervals with the same low and high version. diff --git a/vendor/golang.org/x/mod/modfile/work.go b/vendor/golang.org/x/mod/modfile/work.go index 0c0e521525..75dc1c5491 100644 --- a/vendor/golang.org/x/mod/modfile/work.go +++ b/vendor/golang.org/x/mod/modfile/work.go @@ -12,9 +12,10 @@ import ( // A WorkFile is the parsed, interpreted form of a go.work file. type WorkFile struct { - Go *Go - Use []*Use - Replace []*Replace + Go *Go + Toolchain *Toolchain + Use []*Use + Replace []*Replace Syntax *FileSyntax } @@ -109,7 +110,7 @@ func (f *WorkFile) Cleanup() { func (f *WorkFile) AddGoStmt(version string) error { if !GoVersionRE.MatchString(version) { - return fmt.Errorf("invalid language version string %q", version) + return fmt.Errorf("invalid language version %q", version) } if f.Go == nil { stmt := &Line{Token: []string{"go", version}} @@ -117,7 +118,7 @@ func (f *WorkFile) AddGoStmt(version string) error { Version: version, Syntax: stmt, } - // Find the first non-comment-only block that's and add + // Find the first non-comment-only block and add // the go statement before it. That will keep file comments at the top. i := 0 for i = 0; i < len(f.Syntax.Stmt); i++ { @@ -133,6 +134,56 @@ func (f *WorkFile) AddGoStmt(version string) error { return nil } +func (f *WorkFile) AddToolchainStmt(name string) error { + if !ToolchainRE.MatchString(name) { + return fmt.Errorf("invalid toolchain name %q", name) + } + if f.Toolchain == nil { + stmt := &Line{Token: []string{"toolchain", name}} + f.Toolchain = &Toolchain{ + Name: name, + Syntax: stmt, + } + // Find the go line and add the toolchain line after it. + // Or else find the first non-comment-only block and add + // the toolchain line before it. That will keep file comments at the top. + i := 0 + for i = 0; i < len(f.Syntax.Stmt); i++ { + if line, ok := f.Syntax.Stmt[i].(*Line); ok && len(line.Token) > 0 && line.Token[0] == "go" { + i++ + goto Found + } + } + for i = 0; i < len(f.Syntax.Stmt); i++ { + if _, ok := f.Syntax.Stmt[i].(*CommentBlock); !ok { + break + } + } + Found: + f.Syntax.Stmt = append(append(f.Syntax.Stmt[:i:i], stmt), f.Syntax.Stmt[i:]...) + } else { + f.Toolchain.Name = name + f.Syntax.updateLine(f.Toolchain.Syntax, "toolchain", name) + } + return nil +} + +// DropGoStmt deletes the go statement from the file. +func (f *WorkFile) DropGoStmt() { + if f.Go != nil { + f.Go.Syntax.markRemoved() + f.Go = nil + } +} + +// DropToolchainStmt deletes the toolchain statement from the file. +func (f *WorkFile) DropToolchainStmt() { + if f.Toolchain != nil { + f.Toolchain.Syntax.markRemoved() + f.Toolchain = nil + } +} + func (f *WorkFile) AddUse(diskPath, modulePath string) error { need := true for _, d := range f.Use { diff --git a/vendor/modules.txt b/vendor/modules.txt index 3c0d0b4596..133fb9b4a9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -439,8 +439,8 @@ go.opencensus.io/trace go.opencensus.io/trace/internal go.opencensus.io/trace/propagation go.opencensus.io/trace/tracestate -# go.uber.org/mock v0.2.0 -## explicit; go 1.19 +# go.uber.org/mock v0.3.0 +## explicit; go 1.20 go.uber.org/mock/gomock go.uber.org/mock/mockgen go.uber.org/mock/mockgen/model @@ -448,7 +448,7 @@ go.uber.org/mock/mockgen/model ## explicit; go 1.17 golang.org/x/crypto/curve25519 golang.org/x/crypto/curve25519/internal/field -# golang.org/x/mod v0.10.0 +# golang.org/x/mod v0.11.0 ## explicit; go 1.17 golang.org/x/mod/internal/lazyregexp golang.org/x/mod/modfile