Skip to content

Commit

Permalink
#3 add some tests
Browse files Browse the repository at this point in the history
Signed-off-by: mohemohe <[email protected]>
  • Loading branch information
mohemohe committed May 5, 2019
1 parent 707ecd9 commit d4c49ff
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions s3fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ func setup() {
AccessSecretKey: "secretkey",
Bucket: "test",
})
_ = fs.CreateBucket("test")
}

func teardown() {
if fs != nil {
if err := fs.BulkDelete("/"); err != nil {
println("teardown error:", err.Error())
}
}
// if fs != nil {
// if err := fs.BulkDelete("/"); err != nil {
// println("teardown error:", err.Error())
// }
// }
}

func TestMain(m *testing.M) {
Expand All @@ -37,6 +36,12 @@ func TestMain(m *testing.M) {
os.Exit(exitCode)
}

func TestS3FS_CreateBucket(t *testing.T) {
if err := fs.CreateBucket("test"); err != nil {
t.Fatal("bucket create error:", err)
}
}

func TestS3FS_Put(t *testing.T) {
body := []byte("this is test string")
readCloser := ioutil.NopCloser(bytes.NewReader(body))
Expand Down Expand Up @@ -204,12 +209,39 @@ func TestS3FS_Move(t *testing.T) {
}

func TestS3FS_Delete(t *testing.T) {
if err := fs.Delete("/testfile"); err != nil {
t.Fatal("copy error:", err)
}
t.Run("rm", func(st *testing.T){
if err := fs.Delete("/testfile"); err != nil {
t.Fatal("copy error:", err)
}

_, err := fs.Get("/testfile")
if err == nil {
t.Fatal("io error:", err)
}
_, err := fs.Get("/testfile")
if err == nil {
t.Fatal("io error:", err)
}
})
t.Run("rm -r", func(st *testing.T){
if err := fs.Delete("/"); err != nil {
t.Fatal("copy error:", err)
}
list := fs.List("/")
if list == nil {
t.Fatal("s3 error")
}
if len(*list) != 0 {
t.Fatal("io error")
}
})
}

func TestS3FS_DeleteBucket(t *testing.T) {
t.Run("exists", func(st *testing.T){
if err := fs.DeleteBucket("test"); err != nil {
t.Fatal("bucket delete error:", err)
}
})
t.Run("non exists", func(st *testing.T){
if err := fs.DeleteBucket("dummybucket"); err == nil {
t.Fatal("io error:", err)
}
})
}

0 comments on commit d4c49ff

Please sign in to comment.