pkger/index_test.go

65 lines
1.0 KiB
Go
Raw Normal View History

2019-07-31 23:29:49 +03:00
package pkger
import (
"io"
"os"
"strings"
"testing"
2019-08-01 19:03:12 +03:00
"github.com/markbates/pkger/paths"
2019-07-31 23:29:49 +03:00
"github.com/stretchr/testify/require"
)
func Test_index_Create(t *testing.T) {
r := require.New(t)
i := newIndex()
2019-08-01 19:03:12 +03:00
f, err := i.Create(paths.Path{
2019-07-31 23:29:49 +03:00
Name: "/hello.txt",
})
r.NoError(err)
r.NotNil(f)
fi, err := f.Stat()
r.NoError(err)
r.Equal("/hello.txt", fi.Name())
r.Equal(os.FileMode(0666), fi.Mode())
r.NotZero(fi.ModTime())
her := f.her
r.NotZero(her)
r.Equal("github.com/markbates/pkger", her.ImportPath)
}
func Test_index_Create_Write(t *testing.T) {
r := require.New(t)
i := newIndex()
2019-08-01 19:03:12 +03:00
f, err := i.Create(paths.Path{
2019-07-31 23:29:49 +03:00
Name: "/hello.txt",
})
r.NoError(err)
r.NotNil(f)
fi, err := f.Stat()
r.NoError(err)
r.Zero(fi.Size())
r.Equal("/hello.txt", fi.Name())
mt := fi.ModTime()
r.NotZero(mt)
sz, err := io.Copy(f, strings.NewReader(radio))
r.NoError(err)
r.Equal(int64(1381), sz)
r.NoError(f.Close())
r.Equal(int64(1381), fi.Size())
r.NotZero(fi.ModTime())
r.NotEqual(mt, fi.ModTime())
}