Test that we can write some data to a file and read it back.`
(t *testing.T)
| 30 | |
| 31 | // Test that we can write some data to a file and read it back.` |
| 32 | func TestSimpleWriteRead(t *testing.T) { |
| 33 | ctx := contexttest.Context(t) |
| 34 | fd, cleanup, err := newFileFD(ctx, 0644) |
| 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | defer cleanup() |
| 39 | |
| 40 | // Write. |
| 41 | data := []byte("foobarbaz") |
| 42 | n, err := fd.Write(ctx, usermem.BytesIOSequence(data), vfs.WriteOptions{}) |
| 43 | if err != nil { |
| 44 | t.Fatalf("fd.Write failed: %v", err) |
| 45 | } |
| 46 | if n != int64(len(data)) { |
| 47 | t.Errorf("fd.Write got short write length %d, want %d", n, len(data)) |
| 48 | } |
| 49 | if got, want := fd.Impl().(*regularFileFD).off, int64(len(data)); got != want { |
| 50 | t.Errorf("fd.Write left offset at %d, want %d", got, want) |
| 51 | } |
| 52 | |
| 53 | // Seek back to beginning. |
| 54 | if _, err := fd.Seek(ctx, 0, linux.SEEK_SET); err != nil { |
| 55 | t.Fatalf("fd.Seek failed: %v", err) |
| 56 | } |
| 57 | if got, want := fd.Impl().(*regularFileFD).off, int64(0); got != want { |
| 58 | t.Errorf("fd.Seek(0) left offset at %d, want %d", got, want) |
| 59 | } |
| 60 | |
| 61 | // Read. |
| 62 | buf := make([]byte, len(data)) |
| 63 | n, err = fd.Read(ctx, usermem.BytesIOSequence(buf), vfs.ReadOptions{}) |
| 64 | if err != nil && err != io.EOF { |
| 65 | t.Fatalf("fd.Read failed: %v", err) |
| 66 | } |
| 67 | if n != int64(len(data)) { |
| 68 | t.Errorf("fd.Read got short read length %d, want %d", n, len(data)) |
| 69 | } |
| 70 | if got, want := string(buf), string(data); got != want { |
| 71 | t.Errorf("Read got %q want %s", got, want) |
| 72 | } |
| 73 | if got, want := fd.Impl().(*regularFileFD).off, int64(len(data)); got != want { |
| 74 | t.Errorf("fd.Write left offset at %d, want %d", got, want) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func TestPWrite(t *testing.T) { |
| 79 | ctx := contexttest.Context(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…