tcpip_test.go 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2012 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 !windows
  5. package test
  6. // direct-tcpip functional tests
  7. import (
  8. "net"
  9. "net/http"
  10. "testing"
  11. )
  12. func TestTCPIPHTTP(t *testing.T) {
  13. // google.com will generate at least one redirect, possibly three
  14. // depending on your location.
  15. doTest(t, "http://google.com")
  16. }
  17. func TestTCPIPHTTPS(t *testing.T) {
  18. doTest(t, "https://encrypted.google.com/")
  19. }
  20. func doTest(t *testing.T, url string) {
  21. server := newServer(t)
  22. defer server.Shutdown()
  23. conn := server.Dial()
  24. defer conn.Close()
  25. tr := &http.Transport{
  26. Dial: func(n, addr string) (net.Conn, error) {
  27. return conn.Dial(n, addr)
  28. },
  29. }
  30. client := &http.Client{
  31. Transport: tr,
  32. }
  33. resp, err := client.Get(url)
  34. if err != nil {
  35. t.Fatalf("unable to proxy: %s", err)
  36. }
  37. // got a body without error
  38. t.Log(resp)
  39. }