harness-drone/vendor/code.google.com/p/go.crypto/ssh/test/tcpip_test.go

48 lines
957 B
Go
Raw Normal View History

2015-05-22 18:37:40 +00:00
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !windows
package test
// direct-tcpip functional tests
import (
"net"
2015-09-30 01:21:17 +00:00
"net/http"
2015-05-22 18:37:40 +00:00
"testing"
)
2015-09-30 01:21:17 +00:00
func TestTCPIPHTTP(t *testing.T) {
// google.com will generate at least one redirect, possibly three
// depending on your location.
doTest(t, "http://google.com")
}
func TestTCPIPHTTPS(t *testing.T) {
doTest(t, "https://encrypted.google.com/")
}
func doTest(t *testing.T, url string) {
2015-05-22 18:37:40 +00:00
server := newServer(t)
defer server.Shutdown()
2015-09-30 01:21:17 +00:00
conn := server.Dial(clientConfig())
defer conn.Close()
2015-05-22 18:37:40 +00:00
2015-09-30 01:21:17 +00:00
tr := &http.Transport{
Dial: func(n, addr string) (net.Conn, error) {
return conn.Dial(n, addr)
},
2015-05-22 18:37:40 +00:00
}
2015-09-30 01:21:17 +00:00
client := &http.Client{
Transport: tr,
}
resp, err := client.Get(url)
2015-05-22 18:37:40 +00:00
if err != nil {
2015-09-30 01:21:17 +00:00
t.Fatalf("unable to proxy: %s", err)
2015-05-22 18:37:40 +00:00
}
2015-09-30 01:21:17 +00:00
// got a body without error
t.Log(resp)
2015-05-22 18:37:40 +00:00
}