testcontext: sanitize folder name (#2195)

This commit is contained in:
Egon Elbre 2019-06-13 15:46:08 +03:00 committed by GitHub
parent 380684e766
commit 1a1a084477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"storj.io/storj/cmd/uplink/cmd"
)

View File

@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
@ -113,9 +112,15 @@ func (ctx *Context) Dir(elem ...string) string {
ctx.test.Helper()
ctx.once.Do(func() {
sanitized := strings.Map(func(r rune) rune {
if ('a' <= r && r <= 'z') || ('A' <= r && r <= 'Z') || ('0' <= r && r <= '9') || r == '-' {
return r
}
return '_'
}, ctx.test.Name())
var err error
pattern := regexp.MustCompile(`[\\/]`)
ctx.directory, err = ioutil.TempDir("", pattern.ReplaceAllString(ctx.test.Name(), "_"))
ctx.directory, err = ioutil.TempDir("", sanitized)
if err != nil {
ctx.test.Fatal(err)
}

View File

@ -10,6 +10,7 @@ import (
"github.com/skyrings/skyring-common/tools/uuid"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/pkg/accounting"
"storj.io/storj/pkg/storj"

View File

@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vivint/infectious"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/pkcrypto"
"storj.io/storj/pkg/storj"

View File

@ -7,6 +7,7 @@ import (
"testing"
assert "github.com/stretchr/testify/require"
"storj.io/storj/pkg/macaroon"
)

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/pkg/storj"
)

View File

@ -13,6 +13,7 @@ import (
"testing"
"github.com/zeebo/errs"
"storj.io/storj/internal/testcontext"
"storj.io/storj/storage"
"storj.io/storj/storage/testsuite"

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/memory"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"

View File

@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/pkg/storj"
"storj.io/storj/uplink"