pkger/index_test.go

64 lines
984 B
Go
Raw Normal View History

2019-07-31 23:29:49 +03:00
package pkger
import (
"io"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_index_Create(t *testing.T) {
r := require.New(t)
i := newIndex()
2019-08-02 05:34:32 +03:00
f, err := i.Create(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)
2019-08-02 00:35:42 +03:00
r.Equal("hello.txt", fi.Name())
2019-07-31 23:29:49 +03:00
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-02 05:34:32 +03:00
f, err := i.Create(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())
2019-08-02 00:35:42 +03:00
r.Equal("hello.txt", fi.Name())
2019-07-31 23:29:49 +03:00
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())
}