Files
qvyun/backend/main_test.go
2025-01-16 15:59:21 +08:00

83 lines
1.6 KiB
Go

package main
import (
"errors"
"os"
"path/filepath"
"testing"
"backend/pkg/utils"
. "github.com/smartystreets/goconvey/convey"
"github.com/spf13/afero"
_ "go.beyondstorage.io/services/fs/v4"
"go.beyondstorage.io/v5/services"
"go.beyondstorage.io/v5/types"
)
func Test_mkdir(t *testing.T) {
Convey("Test os.MkdirAll", t, func() {
path := filepath.Join(os.TempDir(), "abc")
defer os.RemoveAll(path)
Convey("first create a directory", func() {
err := os.MkdirAll(path, 0o755)
So(err, ShouldBeNil)
})
Convey("create a directory again", func() {
err := os.MkdirAll(path, 0o755)
So(err, ShouldBeNil)
})
})
}
func Test_storage(t *testing.T) {
Convey("Test storage", t, func() {
Convey("local fs", func() {
store, err := services.NewStoragerFromString("fs:///mnt/yangpingliang/publish/")
So(err, ShouldBeNil)
lst, err := store.List("")
So(err, ShouldBeNil)
for {
o, err := lst.Next()
if err != nil && !errors.Is(err, types.IterateDone) {
break
}
So(err, ShouldBeNil)
t.Logf("Object: %s", o.MustGetContentType())
}
})
})
}
func Test_afero(t *testing.T) {
Convey("Test afero", t, func() {
Convey("local fs", func() {
pathFs := afero.NewBasePathFs(afero.NewOsFs(), "/mnt/yangpingliang/publish/")
lst, err := afero.ReadDir(pathFs, "")
So(err, ShouldBeNil)
for _, fi := range lst {
k := "F"
if fi.IsDir() {
k = "D"
}
if fi.IsDir() {
continue
}
md5, err := utils.FileMd5(filepath.Join("/mnt/yangpingliang/publish/", fi.Name()))
So(err, ShouldBeNil)
t.Logf("[%s]%s, md5: %s", k, fi.Name(), md5)
}
})
})
}