testutils.go 811 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2019 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package testutils
  7. // BlockingRW implements io.Reader and Writer but never returns when called
  8. type BlockingRW struct{ nilChan chan struct{} }
  9. func (rw *BlockingRW) Read(p []byte) (n int, err error) {
  10. <-rw.nilChan
  11. return
  12. }
  13. func (rw *BlockingRW) Write(p []byte) (n int, err error) {
  14. <-rw.nilChan
  15. return
  16. }
  17. // NoopRW implements io.Reader and Writer but never returns when called
  18. type NoopRW struct{}
  19. func (rw *NoopRW) Read(p []byte) (n int, err error) {
  20. return len(p), nil
  21. }
  22. func (rw *NoopRW) Write(p []byte) (n int, err error) {
  23. return len(p), nil
  24. }