Skip to content

Commit

Permalink
use reva gateway client and mocks
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Mar 29, 2023
1 parent 0f95409 commit c1d0a7b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 72 deletions.
1 change: 0 additions & 1 deletion services/graph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ include ../../.make/generate.mk

.PHONY: ci-go-generate
ci-go-generate: $(MOCKERY) # CI runs ci-node-generate automatically before this target
$(MOCKERY) --dir pkg/service/v0 --case underscore --name GatewayClient
$(MOCKERY) --dir pkg/service/v0 --case underscore --name HTTPClient
$(MOCKERY) --dir pkg/service/v0 --case underscore --name Publisher
$(MOCKERY) --dir pkg/service/v0 --case underscore --name Permissions
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
libregraph "github.com/owncloud/libre-graph-api-go"
"github.com/stretchr/testify/mock"

cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
Expand All @@ -33,7 +34,7 @@ var _ = Describe("Applications", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
roleService *mocks.RoleService
identityBackend *identitymocks.Backend
Expand All @@ -46,7 +47,7 @@ var _ = Describe("Applications", func() {

identityBackend = &identitymocks.Backend{}
roleService = &mocks.RoleService{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}

rr = httptest.NewRecorder()
ctx = context.Background()
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/approleassignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
"github.com/golang/protobuf/ptypes/empty"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -37,7 +38,7 @@ var _ = Describe("AppRoleAssignments", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
roleService *mocks.RoleService
identityBackend *identitymocks.Backend
Expand All @@ -56,7 +57,7 @@ var _ = Describe("AppRoleAssignments", func() {

identityBackend = &identitymocks.Backend{}
roleService = &mocks.RoleService{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}

rr = httptest.NewRecorder()
ctx = context.Background()
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/driveitems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/pkg/utils"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
Expand All @@ -34,7 +35,7 @@ var _ = Describe("Driveitems", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
identityBackend *identitymocks.Backend

Expand All @@ -49,7 +50,7 @@ var _ = Describe("Driveitems", func() {
rr = httptest.NewRecorder()

identityBackend = &identitymocks.Backend{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
newGroup = libregraph.NewGroup()
newGroup.SetMembersodataBind([]string{"/users/user1"})
newGroup.SetId("group1")
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/educationclasses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -33,7 +34,7 @@ var _ = Describe("EducationClass", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
identityBackend *identitymocks.Backend
identityEducationBackend *identitymocks.EducationBackend
Expand All @@ -53,7 +54,7 @@ var _ = Describe("EducationClass", func() {

identityEducationBackend = &identitymocks.EducationBackend{}
identityBackend = &identitymocks.Backend{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
newClass = libregraph.NewEducationClass("math", "course")
newClass.SetMembersodataBind([]string{"/users/user1"})
newClass.SetId("math")
Expand Down
6 changes: 3 additions & 3 deletions services/graph/pkg/service/v0/educationschools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -19,7 +20,6 @@ import (
libregraph "github.com/owncloud/libre-graph-api-go"
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
"github.com/owncloud/ocis/v2/services/graph/mocks"
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
identitymocks "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks"
Expand All @@ -36,7 +36,7 @@ var _ = Describe("Schools", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
identityEducationBackend *identitymocks.EducationBackend

rr *httptest.ResponseRecorder
Expand All @@ -51,7 +51,7 @@ var _ = Describe("Schools", func() {

BeforeEach(func() {
identityEducationBackend = &identitymocks.EducationBackend{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
newSchool = libregraph.NewEducationSchool()
newSchool.SetId("school1")

Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/educationuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -38,7 +39,7 @@ var _ = Describe("EducationUsers", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
roleService *mocks.RoleService
identityEducationBackend *identitymocks.EducationBackend
Expand All @@ -57,7 +58,7 @@ var _ = Describe("EducationUsers", func() {

identityEducationBackend = &identitymocks.EducationBackend{}
roleService = &mocks.RoleService{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}

rr = httptest.NewRecorder()
ctx = context.Background()
Expand Down
51 changes: 3 additions & 48 deletions services/graph/pkg/service/v0/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,6 @@ import (

//go:generate make -C ../../.. generate

type GatewayClient = gateway.GatewayAPIClient

/*
// GatewayClient is the subset of the gateway.GatewayAPIClient that is being used to interact with the gateway
type GatewayClient interface {
//gateway.GatewayAPIClient
// Authenticates a user.
Authenticate(ctx context.Context, in *gateway.AuthenticateRequest, opts ...grpc.CallOption) (*gateway.AuthenticateResponse, error)
// Returns the home path for the given authenticated user.
// When a user has access to multiple storage providers, one of them is the home.
GetHome(ctx context.Context, in *provider.GetHomeRequest, opts ...grpc.CallOption) (*provider.GetHomeResponse, error)
// GetPath does a path lookup for a resource by ID
GetPath(ctx context.Context, in *provider.GetPathRequest, opts ...grpc.CallOption) (*provider.GetPathResponse, error)
// Returns a list of resource information
// for the provided reference.
// MUST return CODE_NOT_FOUND if the reference does not exists.
ListContainer(ctx context.Context, in *provider.ListContainerRequest, opts ...grpc.CallOption) (*provider.ListContainerResponse, error)
// Returns the resource information at the provided reference.
// MUST return CODE_NOT_FOUND if the reference does not exist.
Stat(ctx context.Context, in *provider.StatRequest, opts ...grpc.CallOption) (*provider.StatResponse, error)
// TouchFile allows to touch a file
TouchFile(ctx context.Context, req *provider.TouchFileRequest, opts ...grpc.CallOption) (*provider.TouchFileResponse, error)
// Initiates the upload of a file using an out-of-band data transfer mechanism.
InitiateFileUpload(ctx context.Context, in *provider.InitiateFileUploadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileUploadResponse, error)
// Initiates the download of a file using an
// out-of-band data transfer mechanism.
InitiateFileDownload(ctx context.Context, in *provider.InitiateFileDownloadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileDownloadResponse, error)
// Creates a storage space.
CreateStorageSpace(ctx context.Context, in *provider.CreateStorageSpaceRequest, opts ...grpc.CallOption) (*provider.CreateStorageSpaceResponse, error)
// Lists storage spaces.
ListStorageSpaces(ctx context.Context, in *provider.ListStorageSpacesRequest, opts ...grpc.CallOption) (*provider.ListStorageSpacesResponse, error)
// Updates a storage space.
UpdateStorageSpace(ctx context.Context, in *provider.UpdateStorageSpaceRequest, opts ...grpc.CallOption) (*provider.UpdateStorageSpaceResponse, error)
// Deletes a storage space.
DeleteStorageSpace(ctx context.Context, in *provider.DeleteStorageSpaceRequest, opts ...grpc.CallOption) (*provider.DeleteStorageSpaceResponse, error)
// Returns the quota available under the provided
// reference.
// MUST return CODE_NOT_FOUND if the reference does not exist
// MUST return CODE_RESOURCE_EXHAUSTED on exceeded quota limits.
GetQuota(ctx context.Context, in *gateway.GetQuotaRequest, opts ...grpc.CallOption) (*provider.GetQuotaResponse, error)
SetArbitraryMetadata(ctx context.Context, request *provider.SetArbitraryMetadataRequest, opts ...grpc.CallOption) (*provider.SetArbitraryMetadataResponse, error)
}
*/

// Publisher is the interface for events publisher
type Publisher interface {
Publish(string, interface{}, ...mevents.PublishOption) error
Expand All @@ -88,7 +43,7 @@ type HTTPClient interface {
}

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

// RoleService is the interface used to access the role service
type RoleService interface {
Expand All @@ -105,7 +60,7 @@ type Graph struct {
logger *log.Logger
identityBackend identity.Backend
identityEducationBackend identity.EducationBackend
gatewayClient GatewayClient
gatewayClient gateway.GatewayAPIClient
roleService RoleService
permissionsService Permissions
spacePropertiesCache *ttlcache.Cache[string, interface{}]
Expand All @@ -121,7 +76,7 @@ func (g Graph) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// GetGatewayClient returns a gateway client to talk to reva
func (g Graph) GetGatewayClient() GatewayClient {
func (g Graph) GetGatewayClient() gateway.GatewayAPIClient {
return g.gatewayClient
}

Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/pkg/utils"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -38,7 +39,7 @@ import (
var _ = Describe("Graph", func() {
var (
svc service.Service
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
permissionService mocks.Permissions
ctx context.Context
Expand All @@ -63,7 +64,7 @@ var _ = Describe("Graph", func() {
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}

_ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
eventsPublisher = mocks.Publisher{}
permissionService = mocks.Permissions{}
svc, _ = service.NewService(
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -36,7 +37,7 @@ var _ = Describe("Groups", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
identityBackend *identitymocks.Backend

Expand All @@ -54,7 +55,7 @@ var _ = Describe("Groups", func() {
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)

identityBackend = &identitymocks.Backend{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
newGroup = libregraph.NewGroup()
newGroup.SetMembersodataBind([]string{"/users/user1"})
newGroup.SetId("group1")
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package svc
import (
"net/http"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/ocis-pkg/roles"
Expand All @@ -21,7 +22,7 @@ type Options struct {
Config *config.Config
Middleware []func(http.Handler) http.Handler
RequireAdminMiddleware func(http.Handler) http.Handler
GatewayClient GatewayClient
GatewayClient gateway.GatewayAPIClient
IdentityBackend identity.Backend
IdentityEducationBackend identity.EducationBackend
RoleService RoleService
Expand Down Expand Up @@ -71,7 +72,7 @@ func WithRequireAdminMiddleware(val func(http.Handler) http.Handler) Option {
}

// WithGatewayClient provides a function to set the gateway client option.
func WithGatewayClient(val GatewayClient) Option {
func WithGatewayClient(val gateway.GatewayAPIClient) Option {
return func(o *Options) {
o.GatewayClient = val
}
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-ldap/ldap/v3"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -28,7 +29,7 @@ import (
var _ = Describe("Users changing their own password", func() {
var (
svc service.Service
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
ldapClient *mocks.Client
ldapConfig config.LDAP
identityBackend identity.Backend
Expand All @@ -44,7 +45,7 @@ var _ = Describe("Users changing their own password", func() {
cfg = defaults.FullDefaultConfig()
cfg.TokenManager.JWTSecret = "loremipsum"

gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}
ldapClient = mockedLDAPClient()

ldapConfig = config.LDAP{
Expand Down
5 changes: 3 additions & 2 deletions services/graph/pkg/service/v0/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -41,7 +42,7 @@ var _ = Describe("Users", func() {
svc service.Service
ctx context.Context
cfg *config.Config
gatewayClient *mocks.GatewayClient
gatewayClient *cs3mocks.GatewayAPIClient
eventsPublisher mocks.Publisher
roleService *mocks.RoleService
identityBackend *identitymocks.Backend
Expand All @@ -60,7 +61,7 @@ var _ = Describe("Users", func() {

identityBackend = &identitymocks.Backend{}
roleService = &mocks.RoleService{}
gatewayClient = &mocks.GatewayClient{}
gatewayClient = &cs3mocks.GatewayAPIClient{}

rr = httptest.NewRecorder()
ctx = context.Background()
Expand Down

0 comments on commit c1d0a7b

Please sign in to comment.