diff options
| author | Emmanuel T Odeke <emmanuel@orijtech.com> | 2020-08-17 12:25:49 -0700 |
|---|---|---|
| committer | Emmanuel Odeke <emm.odeke@gmail.com> | 2020-08-18 00:08:36 +0000 |
| commit | db4cda2ec0955854c8ff556ac19ec5e67d48d090 (patch) | |
| tree | 5fd92ea1827ca752bf31825cba4428171f5158f4 /src/testing/iotest/example_test.go | |
| parent | 77a11c05d6a6f766c75f804ea9b8796f9a9f85a3 (diff) | |
| download | go-db4cda2ec0955854c8ff556ac19ec5e67d48d090.tar.xz | |
testing/iotest: correct ErrReader signature and remove exported error
Corrects ErrReader's signature to what was accepted in the approved
proposal, and also removes an exported ErrIO which wasn't part of
the proposal and is unnecessary.
The new signature allows users to customize their own errors.
While here, started examples, with ErrReader leading the way.
Updates #38781
Change-Id: Ia7f84721f11061343cfef8b1adc2b7b69bc3f43c
Reviewed-on: https://go-review.googlesource.com/c/go/+/248898
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing/iotest/example_test.go')
| -rw-r--r-- | src/testing/iotest/example_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/testing/iotest/example_test.go b/src/testing/iotest/example_test.go new file mode 100644 index 0000000000..10f6bd38f7 --- /dev/null +++ b/src/testing/iotest/example_test.go @@ -0,0 +1,22 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package iotest_test + +import ( + "errors" + "fmt" + "testing/iotest" +) + +func ExampleErrReader() { + // A reader that always returns a custom error. + r := iotest.ErrReader(errors.New("custom error")) + n, err := r.Read(nil) + fmt.Printf("n: %d\nerr: %q\n", n, err) + + // Output: + // n: 0 + // err: "custom error" +} |
