1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 16:22:26 +08:00

feat(fileutil): add ReadFile func (#140)

This commit is contained in:
o98k
2023-09-23 13:45:02 +08:00
committed by GitHub
parent 073c77e751
commit 781b89d51a
5 changed files with 138 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package fileutil
import (
"io"
"os"
"testing"
@@ -457,3 +458,21 @@ func TestWriteBytesToFile(t *testing.T) {
os.Remove(filepath)
}
func TestReadFile(t *testing.T) {
reader, close, err := ReadFile("https://httpbin.org/robots.txt")
if err != nil {
t.Fail()
}
defer close()
dat, err := io.ReadAll(reader)
if err != nil {
t.Fail()
}
want := `User-agent: *
Disallow: /deny
`
internal.NewAssert(t, "TestReadFile").Equal(want, string(dat))
}