You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nfs/oper_read_test.go

44 lines
930 B
Go

1 year ago
package nfs_test
import (
"git.noahlan.cn/noahlan/ntool/nfs"
"git.noahlan.cn/noahlan/ntool/ntest/assert"
"strings"
"testing"
)
func TestDiscardReader(t *testing.T) {
sr := strings.NewReader("hello")
bs, err := nfs.ReadOrErr(sr)
assert.NoErr(t, err)
assert.Eq(t, []byte("hello"), bs)
sr = strings.NewReader("hello")
assert.Eq(t, []byte("hello"), nfs.GetContents(sr))
sr = strings.NewReader("hello")
nfs.DiscardReader(sr)
assert.Empty(t, nfs.ReadReader(sr))
assert.Empty(t, nfs.ReadAll(sr))
}
func TestGetContents(t *testing.T) {
fpath := "./testdata/get-contents.txt"
assert.NoErr(t, nfs.RmFileIfExist(fpath))
_, err := nfs.PutContents(fpath, "hello")
assert.NoErr(t, err)
assert.Nil(t, nfs.ReadExistFile("/path-not-exist"))
assert.Eq(t, []byte("hello"), nfs.ReadExistFile(fpath))
assert.Panics(t, func() {
nfs.GetContents(45)
})
assert.Panics(t, func() {
nfs.ReadFile("/path-not-exist")
})
}