fake_transport_go14_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build !go1.5
  15. package client
  16. import (
  17. "errors"
  18. "net/http"
  19. )
  20. func (t *fakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
  21. select {
  22. case resp := <-t.respchan:
  23. return resp, nil
  24. case err := <-t.errchan:
  25. return nil, err
  26. case <-t.startCancel:
  27. select {
  28. // this simulates that the request is finished before cancel effects
  29. case resp := <-t.respchan:
  30. return resp, nil
  31. // wait on finishCancel to simulate taking some amount of
  32. // time while calling CancelRequest
  33. case <-t.finishCancel:
  34. return nil, errors.New("cancelled")
  35. }
  36. }
  37. }