mirror of
https://github.com/golang/go
synced 2024-11-23 00:50:05 -07:00
Don't use subtests.
This commit is contained in:
parent
2ab3f8ff53
commit
d9bcc1c0bf
@ -186,54 +186,50 @@ func TestOffset(t *testing.T) {
|
||||
|
||||
const want = "hello, world\n"
|
||||
|
||||
t.Run("Read", func(t *testing.T) {
|
||||
got := make([]byte, len(want))
|
||||
n, err := file.Read(got)
|
||||
if err != nil {
|
||||
t.Fatal("Read:", err)
|
||||
}
|
||||
if n != len(want) {
|
||||
t.Fatal("Read:", n)
|
||||
}
|
||||
if string(got) != want {
|
||||
t.Fatalf("Read: %q", got)
|
||||
}
|
||||
})
|
||||
// Read the entire file.
|
||||
got := make([]byte, len(want))
|
||||
n, err := file.Read(got)
|
||||
if err != nil {
|
||||
t.Fatal("Read:", err)
|
||||
}
|
||||
if n != len(want) {
|
||||
t.Fatal("Read:", n)
|
||||
}
|
||||
if string(got) != want {
|
||||
t.Fatalf("Read: %q", got)
|
||||
}
|
||||
|
||||
t.Run("EOF", func(t *testing.T) {
|
||||
var buf [1]byte
|
||||
n, err := file.Read(buf[:])
|
||||
if err != io.EOF {
|
||||
t.Fatal("Read:", err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Fatal("Read:", n)
|
||||
}
|
||||
})
|
||||
// Try to read one byte; confirm we're at the EOF.
|
||||
var buf [1]byte
|
||||
n, err = file.Read(buf[:])
|
||||
if err != io.EOF {
|
||||
t.Fatal("Read:", err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Fatal("Read:", n)
|
||||
}
|
||||
|
||||
t.Run("Offset", func(t *testing.T) {
|
||||
seeker := file.(io.Seeker)
|
||||
n, err := seeker.Seek(0, io.SeekCurrent)
|
||||
if err != nil {
|
||||
t.Fatal("Read:", err)
|
||||
}
|
||||
if n != int64(len(want)) {
|
||||
t.Fatal("Read:", n)
|
||||
}
|
||||
})
|
||||
// Use seek to get the offset at the EOF.
|
||||
seeker := file.(io.Seeker)
|
||||
off, err := seeker.Seek(0, io.SeekCurrent)
|
||||
if err != nil {
|
||||
t.Fatal("Seek:", err)
|
||||
}
|
||||
if off != int64(len(want)) {
|
||||
t.Fatal("Seek:", off)
|
||||
}
|
||||
|
||||
t.Run("ReadAt", func(t *testing.T) {
|
||||
at := file.(io.ReaderAt)
|
||||
got := make([]byte, len(want))
|
||||
n, err := at.ReadAt(got, 0)
|
||||
if err != nil {
|
||||
t.Fatal("ReadAt:", err)
|
||||
}
|
||||
if n != len(want) {
|
||||
t.Fatal("ReadAt:", n)
|
||||
}
|
||||
if string(got) != want {
|
||||
t.Fatalf("ReadAt: %q", got)
|
||||
}
|
||||
})
|
||||
// Use ReadAt to read the entire file, ignoring the offset.
|
||||
at := file.(io.ReaderAt)
|
||||
got = make([]byte, len(want))
|
||||
n, err = at.ReadAt(got, 0)
|
||||
if err != nil {
|
||||
t.Fatal("ReadAt:", err)
|
||||
}
|
||||
if n != len(want) {
|
||||
t.Fatal("ReadAt:", n)
|
||||
}
|
||||
if string(got) != want {
|
||||
t.Fatalf("ReadAt: %q", got)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user