ctxhttp_17_test.go 628 B

12345678910111213141516171819202122232425262728
  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. ctx := context.Background()
  18. resp, err := Get(ctx, http.DefaultClient, ts.URL)
  19. if resp == nil || err != nil {
  20. t.Fatalf("error received from client: %v %v", err, resp)
  21. }
  22. resp.Body.Close()
  23. }