Skip to content

Commit

Permalink
Add grpc tests for the owncloud driver
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Mar 11, 2021
1 parent dcbf035 commit 11ecdc7
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 16 deletions.
11 changes: 11 additions & 0 deletions tests/integration/grpc/fixtures/storageprovider-owncloud.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[grpc]
address = "{{grpc_address}}"

[grpc.services.storageprovider]
driver = "owncloud"

[grpc.services.storageprovider.drivers.owncloud]
enable_home = true
datadirectory = "{{root}}"
userprovidersvc = "{{users_address}}"
redis = "{{redis_address}}"
45 changes: 37 additions & 8 deletions tests/integration/grpc/grpc_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

const timeoutMs = 30000

var revads = map[string]*Revad{}
var mutex = sync.Mutex{}
var port = 19000

Expand All @@ -47,15 +46,37 @@ func TestGprc(t *testing.T) {
RunSpecs(t, "Gprc Suite")
}

type cleanupFunc func() error
type cleanupFunc func(bool) error

// Revad represents a running revad process
type Revad struct {
TmpRoot string
GrpcAddress string
Cleanup cleanupFunc
TmpRoot string // Temporary directory on disk. Will be cleaned up by the Cleanup func.
GrpcAddress string // Address of the grpc service
Cleanup cleanupFunc // Function to kill the process and cleanup the temp. root. If the given parameter is true the files will be kept to make debugging failures easier.
}

func startRevads(configs map[string]string) (map[string]*Revad, error) {
// stardRevads takes a list of revad configuration files plus a map of
// variables that need to be substituted in them and starts them.
//
// A unique port is assigned to each spawned instance.
// Placeholders in the config files can be replaced the variables from the
// `variables` map, e.g. the config
//
// redis = "{{redis_address}}"
//
// and the variables map
//
// variables = map[string]string{"redis_address": "localhost:6379"}
//
// will result in the config
//
// redis = "localhost:6379"
//
// Special variables are created for the revad addresses, e.g. having a
// `storage` and a `users` revad will make `storage_address` and
// `users_address` available wit the dynamically assigned ports so that
// the services can be made available to each other.
func startRevads(configs map[string]string, variables map[string]string) (map[string]*Revad, error) {
mutex.Lock()
defer mutex.Unlock()

Expand All @@ -82,6 +103,9 @@ func startRevads(configs map[string]string) (map[string]*Revad, error) {
cfg := string(rawCfg)
cfg = strings.ReplaceAll(cfg, "{{root}}", tmpRoot)
cfg = strings.ReplaceAll(cfg, "{{grpc_address}}", ownAddress)
for v, value := range variables {
cfg = strings.ReplaceAll(cfg, "{{"+v+"}}", value)
}
for name, address := range addresses {
cfg = strings.ReplaceAll(cfg, "{{"+name+"_address}}", address)
}
Expand All @@ -99,6 +123,7 @@ func startRevads(configs map[string]string) (map[string]*Revad, error) {
}
defer outfile.Close()
cmd.Stdout = outfile
cmd.Stderr = outfile

err = cmd.Start()
if err != nil {
Expand All @@ -116,13 +141,17 @@ func startRevads(configs map[string]string) (map[string]*Revad, error) {
revad := &Revad{
TmpRoot: tmpRoot,
GrpcAddress: ownAddress,
Cleanup: func() error {
Cleanup: func(keepLogs bool) error {
err := cmd.Process.Signal(os.Kill)
if err != nil {
return errors.Wrap(err, "Could not kill revad")
}
waitForPort(ownAddress, "close")
os.RemoveAll(tmpRoot)
if keepLogs {
fmt.Println("Test failed, keeping root", tmpRoot, "around for debugging")
} else {
os.RemoveAll(tmpRoot)
}
return nil
},
}
Expand Down
94 changes: 88 additions & 6 deletions tests/integration/grpc/storageprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"context"
"io/ioutil"
"os"

"google.golang.org/grpc/metadata"

Expand All @@ -30,6 +31,7 @@ import (
storagep "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/storage/fs/ocis"
"github.com/cs3org/reva/pkg/storage/fs/owncloud"
"github.com/cs3org/reva/pkg/token"
jwt "github.com/cs3org/reva/pkg/token/manager/jwt"
ruser "github.com/cs3org/reva/pkg/user"
Expand All @@ -38,9 +40,17 @@ import (
. "github.com/onsi/gomega"
)

// This test suite tests the gprc storageprovider interface using different
// storage backends
//
// It uses the `startRevads` helper to spawn the according reva daemon and
// other dependencies like a userprovider if needed.
// It also sets up an authenticated context and a service client to the storage
// provider to be used in the assertion functions.
var _ = Describe("storage providers", func() {
var (
dependencies = map[string]string{}
variables = map[string]string{}
revads = map[string]*Revad{}

ctx context.Context
Expand All @@ -53,17 +63,17 @@ var _ = Describe("storage providers", func() {
}

homeRef = &storagep.Reference{
Spec: &storagep.Reference_Path{Path: "/home"},
Spec: &storagep.Reference_Path{Path: "/"},
}
filePath = "/home/file"
filePath = "/file"
fileRef = &storagep.Reference{
Spec: &storagep.Reference_Path{Path: filePath},
}
versionedFilePath = "/home/versionedFile"
versionedFilePath = "/versionedFile"
versionedFileRef = &storagep.Reference{
Spec: &storagep.Reference_Path{Path: versionedFilePath},
}
subdirPath = "/home/subdir"
subdirPath = "/subdir"
subdirRef = &storagep.Reference{
Spec: &storagep.Reference_Path{Path: subdirPath},
}
Expand All @@ -86,15 +96,15 @@ var _ = Describe("storage providers", func() {
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
ctx = ruser.ContextSetUser(ctx, user)

revads, err = startRevads(dependencies)
revads, err = startRevads(dependencies, variables)
Expect(err).ToNot(HaveOccurred())
serviceClient, err = pool.GetStorageProviderServiceClient(revads["storage"].GrpcAddress)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
for _, r := range revads {
Expect(r.Cleanup()).To(Succeed())
Expect(r.Cleanup(CurrentGinkgoTestDescription().Failed)).To(Succeed())
}
})

Expand All @@ -111,6 +121,10 @@ var _ = Describe("storage providers", func() {
statRes, err = serviceClient.Stat(ctx, &storagep.StatRequest{Ref: homeRef})
Expect(err).ToNot(HaveOccurred())
Expect(statRes.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))

ghRes, err := serviceClient.GetHome(ctx, &storagep.GetHomeRequest{})
Expect(err).ToNot(HaveOccurred())
Expect(ghRes.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))
})
}

Expand Down Expand Up @@ -480,4 +494,72 @@ var _ = Describe("storage providers", func() {
assertFileVersions()
})
})

Describe("owncloud", func() {
BeforeEach(func() {
dependencies = map[string]string{
"users": "userprovider-json.toml",
"storage": "storageprovider-owncloud.toml",
}

redisAddress := os.Getenv("REDIS_ADDRESS")
if redisAddress == "" {
Fail("REDIS_ADDRESS not set")
}
variables = map[string]string{
"redis_address": redisAddress,
}
})

assertCreateHome()

Context("with a home and a subdirectory", func() {
JustBeforeEach(func() {
res, err := serviceClient.CreateHome(ctx, &storagep.CreateHomeRequest{})
Expect(err).ToNot(HaveOccurred())
Expect(res.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))

subdirRes, err := serviceClient.CreateContainer(ctx, &storagep.CreateContainerRequest{Ref: subdirRef})
Expect(err).ToNot(HaveOccurred())
Expect(subdirRes.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))
})

assertCreateContainer()
assertListContainer()
assertGetPath()
assertDelete()
assertMove()
assertGrants()
assertUploads()
assertDownloads()
assertRecycle()
assertReferences()
assertMetadata()
})

Context("with an existing file /versioned_file", func() {
JustBeforeEach(func() {
fs, err := owncloud.New(map[string]interface{}{
"datadirectory": revads["storage"].TmpRoot,
"userprovidersvc": revads["users"].GrpcAddress,
"enable_home": true,
})
Expect(err).ToNot(HaveOccurred())

content1 := ioutil.NopCloser(bytes.NewReader([]byte("1")))
content2 := ioutil.NopCloser(bytes.NewReader([]byte("22")))

ctx := ruser.ContextSetUser(context.Background(), user)

err = fs.CreateHome(ctx)
Expect(err).ToNot(HaveOccurred())
err = fs.Upload(ctx, versionedFileRef, content1)
Expect(err).ToNot(HaveOccurred())
err = fs.Upload(ctx, versionedFileRef, content2)
Expect(err).ToNot(HaveOccurred())
})

assertFileVersions()
})
})
})
4 changes: 2 additions & 2 deletions tests/integration/grpc/userprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ var _ = Describe("user providers", func() {
ctx = metadata.AppendToOutgoingContext(ctx, token.TokenHeader, t)
ctx = ruser.ContextSetUser(ctx, user)

revads, err = startRevads(dependencies)
revads, err = startRevads(dependencies, map[string]string{})
Expect(err).ToNot(HaveOccurred())
serviceClient, err = pool.GetUserProviderServiceClient(revads["users"].GrpcAddress)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
for _, r := range revads {
r.Cleanup()
r.Cleanup(CurrentGinkgoTestDescription().Failed)
}
})

Expand Down

0 comments on commit 11ecdc7

Please sign in to comment.