Skip to content

Commit

Permalink
#3 some tests merge into sub 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 92ee6a0 commit 6351415
Showing 1 changed file with 79 additions and 76 deletions.
155 changes: 79 additions & 76 deletions s3fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,7 @@ func TestMain(m *testing.M) {
os.Exit(exitCode)
}

func TestS3FS_List_1(t *testing.T) {
list := fs.List("/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 0 {
t.Fatal("invalid state")
}
}

func TestS3FS_Put1(t *testing.T) {
func TestS3FS_Put(t *testing.T) {
body := []byte("this is test string")
readCloser := ioutil.NopCloser(bytes.NewReader(body))

Expand All @@ -55,29 +45,6 @@ func TestS3FS_Put1(t *testing.T) {
}
}

func TestS3FS_List_2(t *testing.T) {
list := fs.List("/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "testfile" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testfile" {
t.Fatal("invalid file path:", file.Path)
}
if file.Size != int64(len([]byte("this is test string"))) {
t.Fatal("invalid file size:", file.Size)
}
if file.Type != File {
t.Fatal("invalid file type:", file.Type)
}
}

func TestS3FS_Get(t *testing.T) {
t.Run("exists", func(st *testing.T){
readCloser, err := fs.Get("/testfile")
Expand All @@ -101,52 +68,88 @@ func TestS3FS_Get(t *testing.T) {
})
}

func TestS3FS_MkDir(t *testing.T) {
if err := fs.MkDir("/testdir1"); err != nil {
t.Fatal(err)
}
func TestS3FS_List(t *testing.T) {
t.Run("exists", func(st *testing.T){
list := fs.List("/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "testfile" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testfile" {
t.Fatal("invalid file path:", file.Path)
}
if file.Size != int64(len([]byte("this is test string"))) {
t.Fatal("invalid file size:", file.Size)
}
if file.Type != File {
t.Fatal("invalid file type:", file.Type)
}
})
t.Run("non exists", func(st *testing.T){
list := fs.List("/dummydir/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 0 {
t.Fatal("invalid state")
}
})

list := fs.List("/testdir1")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "testdir1" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testdir1/" {
t.Fatal("invalid file path:", file.Path)
}
if file.Type != Directory {
t.Fatal("invalid file type:", file.Type)
}
}

func TestS3FS_MkDirP(t *testing.T) {
if err := fs.MkDir("/testdir2/child"); err != nil {
t.Fatal(err)
}
func TestS3FS_MkDir(t *testing.T) {
t.Run("mkdir", func(st *testing.T){
if err := fs.MkDir("/testdir1"); err != nil {
t.Fatal(err)
}

list := fs.List("/testdir2/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "child" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testdir2/child/" {
t.Fatal("invalid file path:", file.Path)
}
if file.Type != Directory {
t.Fatal("invalid file type:", file.Type)
}
list := fs.List("/testdir1")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "testdir1" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testdir1/" {
t.Fatal("invalid file path:", file.Path)
}
if file.Type != Directory {
t.Fatal("invalid file type:", file.Type)
}
})
t.Run("mkdir -p", func(st *testing.T){
if err := fs.MkDir("/testdir2/child"); err != nil {
t.Fatal(err)
}

list := fs.List("/testdir2/")
if list == nil {
t.Fatal("cannot connect s3")
}
if len(*list) != 1 {
t.Fatal("invalid state")
}
file := (*list)[0]
if file.Name != "child" {
t.Fatal("invalid file name:", file.Name)
}
if file.Path != "/testdir2/child/" {
t.Fatal("invalid file path:", file.Path)
}
if file.Type != Directory {
t.Fatal("invalid file type:", file.Type)
}
})
}

func TestS3FS_Copy(t *testing.T) {
Expand Down

0 comments on commit 6351415

Please sign in to comment.