ctxhttp_17_test.go 646 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2015 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. // +build !plan9,go1.7
  5. package ctxhttp
  6. import (
  7. "io"
  8. "net/http"
  9. "net/http/httptest"
  10. "testing"
  11. "context"
  12. )
  13. func TestGo17Context(t *testing.T) {
  14. ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  15. io.WriteString(w, "ok")
  16. }))
  17. defer ts.Close()
  18. ctx := context.Background()
  19. resp, err := Get(ctx, http.DefaultClient, ts.URL)
  20. if resp == nil || err != nil {
  21. t.Fatalf("error received from client: %v %v", err, resp)
  22. }
  23. resp.Body.Close()
  24. }