Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] DRY up tests by keeping cs3 mocks in a central place #2748

Merged
merged 5 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 0 additions & 430 deletions internal/grpc/services/sharesstorageprovider/mocks/GatewayClient.go

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,6 @@ import (
"github.com/pkg/errors"
)

//go:generate make --no-print-directory -C ../../../.. mockery NAME=GatewayClient
//go:generate make --no-print-directory -C ../../../.. mockery NAME=SharesProviderClient

// GatewayClient describe the interface of a gateway client
type GatewayClient interface {
GetPath(ctx context.Context, in *provider.GetPathRequest, opts ...grpc.CallOption) (*provider.GetPathResponse, error)
Stat(ctx context.Context, in *provider.StatRequest, opts ...grpc.CallOption) (*provider.StatResponse, error)
Move(ctx context.Context, in *provider.MoveRequest, opts ...grpc.CallOption) (*provider.MoveResponse, error)
Delete(ctx context.Context, in *provider.DeleteRequest, opts ...grpc.CallOption) (*provider.DeleteResponse, error)
CreateContainer(ctx context.Context, in *provider.CreateContainerRequest, opts ...grpc.CallOption) (*provider.CreateContainerResponse, error)
ListContainer(ctx context.Context, in *provider.ListContainerRequest, opts ...grpc.CallOption) (*provider.ListContainerResponse, error)
ListFileVersions(ctx context.Context, req *provider.ListFileVersionsRequest, opts ...grpc.CallOption) (*provider.ListFileVersionsResponse, error)
RestoreFileVersion(ctx context.Context, req *provider.RestoreFileVersionRequest, opts ...grpc.CallOption) (*provider.RestoreFileVersionResponse, error)
InitiateFileDownload(ctx context.Context, req *provider.InitiateFileDownloadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileDownloadResponse, error)
InitiateFileUpload(ctx context.Context, req *provider.InitiateFileUploadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileUploadResponse, error)
SetArbitraryMetadata(ctx context.Context, req *provider.SetArbitraryMetadataRequest, opts ...grpc.CallOption) (*provider.SetArbitraryMetadataResponse, error)
UnsetArbitraryMetadata(ctx context.Context, req *provider.UnsetArbitraryMetadataRequest, opts ...grpc.CallOption) (*provider.UnsetArbitraryMetadataResponse, error)
ListReceivedShares(ctx context.Context, req *collaboration.ListReceivedSharesRequest, opts ...grpc.CallOption) (*collaboration.ListReceivedSharesResponse, error)
}

// SharesProviderClient provides methods for listing and modifying received shares
type SharesProviderClient interface {
ListReceivedShares(ctx context.Context, req *collaboration.ListReceivedSharesRequest, opts ...grpc.CallOption) (*collaboration.ListReceivedSharesResponse, error)
UpdateReceivedShare(ctx context.Context, req *collaboration.UpdateReceivedShareRequest, opts ...grpc.CallOption) (*collaboration.UpdateReceivedShareResponse, error)
}

func init() {
rgrpc.Register("sharesstorageprovider", NewDefault)
}
Expand All @@ -84,8 +58,8 @@ type config struct {
}

type service struct {
gateway GatewayClient
sharesProviderClient SharesProviderClient
gateway gateway.GatewayAPIClient
sharesProviderClient collaboration.CollaborationAPIClient
}

func (s *service) Close() error {
Expand Down Expand Up @@ -122,7 +96,7 @@ func NewDefault(m map[string]interface{}, _ *grpc.Server) (rgrpc.Service, error)
}

// New returns a new instance of the SharesStorageProvider service
func New(gateway GatewayClient, c SharesProviderClient) (rgrpc.Service, error) {
func New(gateway gateway.GatewayAPIClient, c collaboration.CollaborationAPIClient) (rgrpc.Service, error) {
s := &service{
gateway: gateway,
sharesProviderClient: c,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
provider "github.com/cs3org/reva/v2/internal/grpc/services/sharesstorageprovider"
mocks "github.com/cs3org/reva/v2/internal/grpc/services/sharesstorageprovider/mocks"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
_ "github.com/cs3org/reva/v2/pkg/share/manager/loader"
"github.com/cs3org/reva/v2/pkg/utils"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"google.golang.org/grpc"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -125,14 +125,14 @@ var _ = Describe("Sharesstorageprovider", func() {
})

s sprovider.ProviderAPIServer
gw *mocks.GatewayClient
sharesProviderClient *mocks.SharesProviderClient
gw *cs3mocks.GatewayAPIClient
sharesProviderClient *cs3mocks.CollaborationAPIClient
)

BeforeEach(func() {
sharesProviderClient = &mocks.SharesProviderClient{}
sharesProviderClient = &cs3mocks.CollaborationAPIClient{}

gw = &mocks.GatewayClient{}
gw = &cs3mocks.GatewayAPIClient{}

// mock stat requests
gw.On("Stat", mock.Anything, mock.AnythingOfType("*providerv1beta1.StatRequest")).Return(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ import (
"go.opentelemetry.io/otel/codes"
)

//go:generate make --no-print-directory -C ../../../../../.. mockery NAME=GatewayClient

const (
_spaceTypeProject = "project"
)
Expand Down Expand Up @@ -155,13 +153,8 @@ func NewMultiStatusResponseXML() *MultiStatusResponseXML {
}
}

// GatewayClient is the interface that's being used to interact with the gateway
type GatewayClient interface {
gateway.GatewayAPIClient
}

// GetGatewayServiceClientFunc is a callback used to pass in a StorageProviderClient during testing
type GetGatewayServiceClientFunc func() (GatewayClient, error)
type GetGatewayServiceClientFunc func() (gateway.GatewayAPIClient, error)

// Handler handles propfind requests
type Handler struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import (
"net/http/httptest"
"strings"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/propfind"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/propfind/mocks"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc"

Expand All @@ -44,7 +45,7 @@ import (
var _ = Describe("Propfind", func() {
var (
handler *propfind.Handler
client *mocks.GatewayClient
client *mocks.GatewayAPIClient
ctx context.Context

readResponse = func(r io.Reader) (*propfind.MultiStatusResponseUnmarshalXML, string, error) {
Expand Down Expand Up @@ -150,8 +151,8 @@ var _ = Describe("Propfind", func() {

JustBeforeEach(func() {
ctx = context.WithValue(context.Background(), net.CtxKeyBaseURI, "http://127.0.0.1:3000")
client = &mocks.GatewayClient{}
handler = propfind.NewHandler("127.0.0.1:3000", func() (propfind.GatewayClient, error) {
client = &mocks.GatewayAPIClient{}
handler = propfind.NewHandler("127.0.0.1:3000", func() (gateway.GatewayAPIClient, error) {
return client, nil
})

Expand Down
3 changes: 2 additions & 1 deletion internal/http/services/owncloud/ocdav/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"path"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/errors"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net"
Expand Down Expand Up @@ -75,7 +76,7 @@ func (h *SpacesHandler) Handler(s *svc, trashbinHandler *TrashbinHandler) http.H

switch r.Method {
case MethodPropfind:
p := propfind.NewHandler(config.PublicURL, func() (propfind.GatewayClient, error) {
p := propfind.NewHandler(config.PublicURL, func() (gateway.GatewayAPIClient, error) {
return pool.GetGatewayServiceClient(config.GatewaySvc)
})
p.HandleSpacesPropfind(w, r, spaceID)
Expand Down
3 changes: 2 additions & 1 deletion internal/http/services/owncloud/ocdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"path"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/errors"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/propfind"
"github.com/cs3org/reva/v2/pkg/appctx"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (h *WebDavHandler) Handler(s *svc) http.Handler {

switch r.Method {
case MethodPropfind:
p := propfind.NewHandler(config.PublicURL, func() (propfind.GatewayClient, error) {
p := propfind.NewHandler(config.PublicURL, func() (gateway.GatewayAPIClient, error) {
return pool.GetGatewayServiceClient(config.GatewaySvc)
})
p.HandlePathPropfind(w, r, ns)
Expand Down
Loading