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) {
|
||||
if w.name == "" {
|
||||
return 0, gcsfs.ErrEmptyObjectName
|
||||
}
|
||||
|
||||
if w.file == nil {
|
||||
w.file, err = w.fs.Create(w.name)
|
||||
if err != nil {
|
||||
|
@ -157,6 +161,9 @@ func (w *writerMock) Write(p []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
func (w *writerMock) Close() error {
|
||||
if w.name == "" {
|
||||
return gcsfs.ErrEmptyObjectName
|
||||
}
|
||||
if w.file == nil {
|
||||
var err error
|
||||
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) {
|
||||
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")
|
||||
var err error
|
||||
|
||||
|
@ -739,9 +748,19 @@ func TestGcsMkdir(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("could not delete the folder %s after the test with error: %s", dirName, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
err := gcsAfs.MkdirAll(dirName, 0755)
|
||||
|
@ -784,4 +803,5 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("failed to remove the folder %s with error: %s", filepath.Join(bucketName, "a"), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue