forked from mirror/afero
Added test cases for `Mkdir` & `MkdirAll` to cover empty folder names
This commit is contained in:
parent
78acf3b074
commit
13ee679c8e
|
@ -146,6 +146,10 @@ type writerMock struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writerMock) Write(p []byte) (n int, err error) {
|
func (w *writerMock) Write(p []byte) (n int, err error) {
|
||||||
|
if w.name == "" {
|
||||||
|
return 0, gcsfs.ErrEmptyObjectName
|
||||||
|
}
|
||||||
|
|
||||||
if w.file == nil {
|
if w.file == nil {
|
||||||
w.file, err = w.fs.Create(w.name)
|
w.file, err = w.fs.Create(w.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -157,6 +161,9 @@ func (w *writerMock) Write(p []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writerMock) Close() error {
|
func (w *writerMock) Close() error {
|
||||||
|
if w.name == "" {
|
||||||
|
return gcsfs.ErrEmptyObjectName
|
||||||
|
}
|
||||||
if w.file == nil {
|
if w.file == nil {
|
||||||
var err error
|
var err error
|
||||||
if strings.HasSuffix(w.name, "/") {
|
if strings.HasSuffix(w.name, "/") {
|
||||||
|
|
20
gcs_test.go
20
gcs_test.go
|
@ -712,6 +712,15 @@ func TestGcsGlob(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGcsMkdir(t *testing.T) {
|
func TestGcsMkdir(t *testing.T) {
|
||||||
|
t.Run("empty", func(t *testing.T) {
|
||||||
|
emptyDirName := bucketName
|
||||||
|
|
||||||
|
err := gcsAfs.Mkdir(emptyDirName, 0755)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("did not fail upon creation of an empty folder")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("success", func(t *testing.T) {
|
||||||
dirName := filepath.Join(bucketName, "a-test-dir")
|
dirName := filepath.Join(bucketName, "a-test-dir")
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -739,9 +748,19 @@ func TestGcsMkdir(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not delete the folder %s after the test with error: %s", dirName, err)
|
t.Fatalf("could not delete the folder %s after the test with error: %s", dirName, err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGcsMkdirAll(t *testing.T) {
|
func TestGcsMkdirAll(t *testing.T) {
|
||||||
|
t.Run("empty", func(t *testing.T) {
|
||||||
|
emptyDirName := bucketName
|
||||||
|
|
||||||
|
err := gcsAfs.MkdirAll(emptyDirName, 0755)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("did not fail upon creation of an empty folder")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("success", func(t *testing.T) {
|
||||||
dirName := filepath.Join(bucketName, "a/b/c")
|
dirName := filepath.Join(bucketName, "a/b/c")
|
||||||
|
|
||||||
err := gcsAfs.MkdirAll(dirName, 0755)
|
err := gcsAfs.MkdirAll(dirName, 0755)
|
||||||
|
@ -784,4 +803,5 @@ func TestGcsMkdirAll(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to remove the folder %s with error: %s", filepath.Join(bucketName, "a"), err)
|
t.Fatalf("failed to remove the folder %s with error: %s", filepath.Join(bucketName, "a"), err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue