MCPcopy Create free account
hub / github.com/chain/txvm / TestWriter

Function TestWriter

errors/writer_test.go:8–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestWriter(t *testing.T) {
9 errX := New("x")
10 tw := testWriter{nil, errX, nil}
11 w := NewWriter(&tw)
12 _, err := w.Write([]byte{1})
13 if err != nil {
14 t.Error("unexpected error", err)
15 }
16 if g := w.Written(); g != 1 {
17 t.Errorf("w.Written() = %d want 1", g)
18 }
19 if len(tw) != 2 {
20 t.Errorf("len(tw) = %d want 2", len(tw))
21 }
22 for i := 0; i < 10; i++ {
23 _, err = w.Write([]byte{1})
24 if err != errX {
25 t.Errorf("err = %v want %v", err, errX)
26 }
27 if g := w.Written(); g != 2 {
28 t.Errorf("w.Written() = %d want 2", g)
29 }
30 if len(tw) != 1 {
31 t.Errorf("len(tw) = %d want 1", len(tw))
32 }
33 }
34 if got := w.Err(); got != errX {
35 t.Errorf("w.Err() = %v want %v", got, errX)
36 }
37}
38
39// testWriter returns its errors in order.
40// elements of a testWriter may be nil.

Callers

nothing calls this directly

Calls 6

WriteMethod · 0.95
WrittenMethod · 0.95
ErrMethod · 0.95
NewWriterFunction · 0.85
ErrorMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected