| 1 |
// Copyright 2020 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package iotest_test |
| 6 |
|
| 7 |
import ( |
| 8 |
"errors" |
| 9 |
"fmt" |
| 10 |
"testing/iotest" |
| 11 |
) |
| 12 |
|
| 13 |
func ExampleErrReader() { |
| 14 |
// A reader that always returns a custom error. |
| 15 |
r := iotest.ErrReader(errors.New("custom error")) |
| 16 |
n, err := r.Read(nil) |
| 17 |
fmt.Printf("n: %d\nerr: %q\n", n, err) |
| 18 |
|
| 19 |
// Output: |
| 20 |
// n: 0 |
| 21 |
// err: "custom error" |
| 22 |
} |