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] Place temporary test directories in reva/tmp #1532

Merged
merged 1 commit into from
Mar 17, 2021
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ composer.lock
vendor-bin/**/vendor
vendor-bin/**/composer.lock
tests/acceptance/output
tmp/

6 changes: 3 additions & 3 deletions pkg/storage/fs/ocis/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"io/ioutil"
"os"
"path"
"strings"

"github.com/cs3org/reva/pkg/storage/fs/ocis/blobstore"
"github.com/cs3org/reva/tests/helpers"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -43,7 +43,7 @@ var _ = Describe("Blobstore", func() {

BeforeEach(func() {
var err error
tmpRoot, err = ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err = helpers.TempDir("reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

data = []byte("1234567890")
Expand All @@ -55,7 +55,7 @@ var _ = Describe("Blobstore", func() {
})

AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
if tmpRoot != "" {
os.RemoveAll(tmpRoot)
}
})
Expand Down
7 changes: 3 additions & 4 deletions pkg/storage/fs/ocis/ocis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package ocis_test

import (
"io/ioutil"
"os"
"strings"

"github.com/cs3org/reva/pkg/storage/fs/ocis"
"github.com/cs3org/reva/tests/helpers"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -36,7 +35,7 @@ var _ = Describe("Ocis", func() {
)

BeforeEach(func() {
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

options = map[string]interface{}{
Expand All @@ -47,7 +46,7 @@ var _ = Describe("Ocis", func() {
})

AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
if tmpRoot != "" {
os.RemoveAll(tmpRoot)
}
})
Expand Down
7 changes: 3 additions & 4 deletions pkg/storage/fs/s3ng/s3ng_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package s3ng_test

import (
"io/ioutil"
"os"
"strings"

"github.com/cs3org/reva/pkg/storage/fs/s3ng"
"github.com/cs3org/reva/tests/helpers"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -36,7 +35,7 @@ var _ = Describe("S3ng", func() {
)

BeforeEach(func() {
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

options = map[string]interface{}{
Expand All @@ -52,7 +51,7 @@ var _ = Describe("S3ng", func() {
})

AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
if tmpRoot != "" {
os.RemoveAll(tmpRoot)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io/ioutil"
"os"
"path"
"strings"
"sync"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs"
treemocks "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree/mocks"
"github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/tests/helpers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand All @@ -46,7 +46,7 @@ var _ = Describe("Decomposed", func() {
)

BeforeEach(func() {
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

options = map[string]interface{}{
Expand Down Expand Up @@ -77,7 +77,7 @@ var _ = Describe("Decomposed", func() {
})

AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
if tmpRoot != "" {
os.RemoveAll(tmpRoot)
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/testhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package helpers

import (
"context"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -36,6 +35,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree"
treemocks "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree/mocks"
ruser "github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/tests/helpers"
)

// TestEnv represents a test environment for unit tests
Expand All @@ -57,7 +57,7 @@ type TestEnv struct {
// /dir1/file1
// /dir1/subdir1/
func NewTestEnv() (*TestEnv, error) {
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root")
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"io/ioutil"
"os"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand All @@ -37,6 +36,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree"
treemocks "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree/mocks"
ruser "github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/tests/helpers"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -70,7 +70,7 @@ var _ = Describe("File uploads", func() {
}
ctx = ruser.ContextSetUser(context.Background(), user)

tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
tmpRoot, err := helpers.TempDir("reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

o, err = options.New(map[string]interface{}{
Expand All @@ -84,7 +84,7 @@ var _ = Describe("File uploads", func() {

AfterEach(func() {
root := o.Root
if strings.HasPrefix(root, os.TempDir()) {
if root != "" {
os.RemoveAll(root)
}
})
Expand Down
46 changes: 46 additions & 0 deletions tests/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018-2021 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package helpers

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
)

// TempDir creates a temporary directory in tmp/ and returns its path
//
// Temporary test directories are created in reva/tmp because system
// /tmp directories are often tmpfs mounts which do not support user
// extended attributes.
func TempDir(name string) (string, error) {
_, currentFileName, _, _ := runtime.Caller(0)
tmpDir := filepath.Join(filepath.Dir(currentFileName), "../../tmp")
err := os.MkdirAll(tmpDir, 0755)
if err != nil {
return "nil", err
}
tmpRoot, err := ioutil.TempDir(tmpDir, "reva-unit-tests-*-root")
if err != nil {
return "nil", err
}

return tmpRoot, nil
}