pipe_test.go 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 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. package http2
  5. import (
  6. "bytes"
  7. "errors"
  8. "io"
  9. "testing"
  10. )
  11. func TestPipeClose(t *testing.T) {
  12. var p pipe
  13. p.b = new(bytes.Buffer)
  14. a := errors.New("a")
  15. b := errors.New("b")
  16. p.CloseWithError(a)
  17. p.CloseWithError(b)
  18. _, err := p.Read(make([]byte, 1))
  19. if err != a {
  20. t.Errorf("err = %v want %v", err, a)
  21. }
  22. }
  23. func TestPipeDoneChan(t *testing.T) {
  24. var p pipe
  25. done := p.Done()
  26. select {
  27. case <-done:
  28. t.Fatal("done too soon")
  29. default:
  30. }
  31. p.CloseWithError(io.EOF)
  32. select {
  33. case <-done:
  34. default:
  35. t.Fatal("should be done")
  36. }
  37. }
  38. func TestPipeDoneChan_ErrFirst(t *testing.T) {
  39. var p pipe
  40. p.CloseWithError(io.EOF)
  41. done := p.Done()
  42. select {
  43. case <-done:
  44. default:
  45. t.Fatal("should be done")
  46. }
  47. }