diff --git a/hack/update-estimator-protobuf.sh b/hack/update-estimator-protobuf.sh index 117bf207f..fe32a4df7 100755 --- a/hack/update-estimator-protobuf.sh +++ b/hack/update-estimator-protobuf.sh @@ -14,6 +14,7 @@ export PATH=$PATH:$GOPATH/bin GO111MODULE=on go install golang.org/x/tools/cmd/goimports GO111MODULE=on go install k8s.io/code-generator/cmd/go-to-protobuf GO111MODULE=on go install github.com/gogo/protobuf/protoc-gen-gogo +GO111MODULE=on go install github.com/vektra/mockery/v2 #ref https://github.com/kubernetes/kubernetes/blob/master/hack/update-generated-protobuf-dockerized.sh if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3."* ]]; then @@ -46,16 +47,7 @@ ${GOPATH}/bin/go-to-protobuf \ --proto-import="${KARMADA_ROOT}/vendor" \ --proto-import="${KARMADA_ROOT}/third_party/protobuf" +go generate ./pkg/estimator/service # The `go-to-protobuf` tool will modify all import proto files in vendor, so we should use go mod vendor to prevent. go mod vendor - -SERVICE_PROTO_FILES=$(find ./pkg/ -name "service.proto") - -for file in ${SERVICE_PROTO_FILES[*]}; do - protoc \ - --proto_path=. \ - --proto_path=./vendor \ - --gogo_out=plugins=grpc:. \ - $file -done diff --git a/pkg/estimator/service/doc.go b/pkg/estimator/service/doc.go new file mode 100644 index 000000000..84f8ac398 --- /dev/null +++ b/pkg/estimator/service/doc.go @@ -0,0 +1,4 @@ +package service + +//go:generate protoc --gogo_opt=paths=source_relative -I . -I ../../.. -I ../../../vendor --gogo_out=plugins=grpc:. --gogo_opt=Mpkg/estimator/pb/generated.proto=github.com/karmada-io/karmada/pkg/estimator/pb service.proto +//go:generate mockery --name=EstimatorClient --inpackage diff --git a/pkg/estimator/service/mock_EstimatorClient.go b/pkg/estimator/service/mock_EstimatorClient.go new file mode 100644 index 000000000..387d26ea8 --- /dev/null +++ b/pkg/estimator/service/mock_EstimatorClient.go @@ -0,0 +1,78 @@ +// Code generated by mockery v2.9.4. DO NOT EDIT. + +package service + +import ( + context "context" + + grpc "google.golang.org/grpc" + + mock "github.com/stretchr/testify/mock" + + pb "github.com/karmada-io/karmada/pkg/estimator/pb" +) + +// MockEstimatorClient is an autogenerated mock type for the EstimatorClient type +type MockEstimatorClient struct { + mock.Mock +} + +// GetUnschedulableReplicas provides a mock function with given fields: ctx, in, opts +func (_m *MockEstimatorClient) GetUnschedulableReplicas(ctx context.Context, in *pb.UnschedulableReplicasRequest, opts ...grpc.CallOption) (*pb.UnschedulableReplicasResponse, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *pb.UnschedulableReplicasResponse + if rf, ok := ret.Get(0).(func(context.Context, *pb.UnschedulableReplicasRequest, ...grpc.CallOption) *pb.UnschedulableReplicasResponse); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pb.UnschedulableReplicasResponse) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *pb.UnschedulableReplicasRequest, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MaxAvailableReplicas provides a mock function with given fields: ctx, in, opts +func (_m *MockEstimatorClient) MaxAvailableReplicas(ctx context.Context, in *pb.MaxAvailableReplicasRequest, opts ...grpc.CallOption) (*pb.MaxAvailableReplicasResponse, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *pb.MaxAvailableReplicasResponse + if rf, ok := ret.Get(0).(func(context.Context, *pb.MaxAvailableReplicasRequest, ...grpc.CallOption) *pb.MaxAvailableReplicasResponse); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pb.MaxAvailableReplicasResponse) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *pb.MaxAvailableReplicasRequest, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +}