github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/testing/iotest/example_test.go (about) 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 "github.com/shogo82148/std/errors" 9 "github.com/shogo82148/std/fmt" 10 "github.com/shogo82148/std/testing/iotest" 11 ) 12 13 func ExampleErrReader() { 14 // 常にカスタムエラーを返すリーダー。 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 }