viper-app/pkg/file/file_test.go

65 lines
1.0 KiB
Go

package file
import (
"crypto/md5"
"fmt"
"os"
"path/filepath"
"testing"
)
func TestFileMD5(t *testing.T) {
t.Log(MD5("test.txt"))
readFile, err := os.ReadFile("test.txt")
if err != nil {
t.Fatal(err)
}
t.Log(fmt.Sprintf("%x", md5.Sum(readFile)))
}
func TestS(t *testing.T) {
t.Run("复用数组", func(t *testing.T) {
fns := []string{"11", "22"}
for idx, fn := range fns {
if idx == 0 {
fns = fns[0:0]
}
t.Log(len(fns), cap(fns))
fns = append(fns, fn+"::")
}
t.Log(len(fns), cap(fns), fns)
})
t.Run("for range 改变数组", func(t *testing.T) {
arr := []int{11, 22, 33}
for idx, v := range arr {
if idx < len(arr)-1 {
arr[idx+1]++
}
t.Log(v)
}
})
}
func TestScan(t *testing.T) {
var (
err error
head string
)
err = DirScan("../data", func(dir string, info os.FileInfo) {
if info.IsDir() {
head = "-"
} else {
head = "|"
}
t.Log(head, filepath.Join(dir, info.Name()), "size(byte):", info.Size())
})
if err != nil {
t.Fatal(err)
}
}