2023-05-13 00:55:47 +08:00
|
|
|
package file
|
2023-02-03 16:18:31 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-05-13 00:55:47 +08:00
|
|
|
"path/filepath"
|
2023-02-03 16:18:31 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFileMD5(t *testing.T) {
|
2023-05-13 00:55:47 +08:00
|
|
|
t.Log(MD5("test.txt"))
|
2023-02-03 16:18:31 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-05-13 00:55:47 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|