github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/context/ctxhttp/ctxhttp_17_test.go (about)

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