pkger/pkging/info_test.go

83 lines
1.4 KiB
Go
Raw Permalink Normal View History

2019-09-22 00:07:49 +03:00
package pkging
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func Test_NewFileInfo(t *testing.T) {
in := []string{
2019-10-18 19:24:51 +03:00
"/public/images/img1.png",
"public/images/img1.png",
"/public\\images/img1.png",
"public/images\\img1.png",
"\\public\\images\\img1.png",
"public\\images\\img1.png",
"\\public/images\\img1.png",
"public\\images/img1.png",
"\\public\\images\\img1.png",
2019-09-22 00:07:49 +03:00
}
2019-10-18 19:24:51 +03:00
const exp = "/public/images/img1.png"
2019-09-22 00:07:49 +03:00
for _, n := range in {
t.Run(n, func(st *testing.T) {
r := require.New(st)
f1 := &FileInfo{
Details: Details{
Name: n,
Size: 42,
Mode: os.FileMode(0644),
IsDir: true,
},
}
f2 := NewFileInfo(f1)
r.Equal(exp, f2.Name())
r.Equal(f1.Size(), f2.Size())
r.Equal(f1.Mode(), f2.Mode())
r.Equal(f1.IsDir(), f2.IsDir())
})
}
}
2019-09-22 00:11:07 +03:00
func Test_WithName(t *testing.T) {
f1 := &FileInfo{
Details: Details{
Name: "/walls/crumbling",
Size: 42,
Mode: os.FileMode(0644),
IsDir: true,
},
}
2019-10-18 19:24:51 +03:00
const exp = "/public/images/img1.png"
2019-09-22 00:11:07 +03:00
in := []string{
2019-10-18 19:24:51 +03:00
"/public/images/img1.png",
"public/images/img1.png",
"/public\\images/img1.png",
"public/images\\img1.png",
"\\public\\images\\img1.png",
"public\\images\\img1.png",
"\\public/images\\img1.png",
"public\\images/img1.png",
"\\public\\images\\img1.png",
2019-09-22 00:11:07 +03:00
}
for _, n := range in {
t.Run(n, func(st *testing.T) {
r := require.New(st)
f2 := WithName(n, f1)
r.Equal(exp, f2.Name())
})
}
}