summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/braintree/manners/helpers_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-09-23 10:17:51 -0400
committerGitHub <noreply@github.com>2016-09-23 10:17:51 -0400
commit2ca0e8f9a0f9863555a26e984cde15efff9ef8f8 (patch)
treedaae1ee67b14a3d0a84424f2a304885d9e75ce2b /vendor/github.com/braintree/manners/helpers_test.go
parent6d62d65b2dc85855aabea036cbd44f6059e19d13 (diff)
downloadchat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.tar.gz
chat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.tar.bz2
chat-2ca0e8f9a0f9863555a26e984cde15efff9ef8f8.zip
Updating golang dependancies (#4075)
Diffstat (limited to 'vendor/github.com/braintree/manners/helpers_test.go')
-rw-r--r--vendor/github.com/braintree/manners/helpers_test.go141
1 files changed, 128 insertions, 13 deletions
diff --git a/vendor/github.com/braintree/manners/helpers_test.go b/vendor/github.com/braintree/manners/helpers_test.go
index 3c11a081d..ba1422cb4 100644
--- a/vendor/github.com/braintree/manners/helpers_test.go
+++ b/vendor/github.com/braintree/manners/helpers_test.go
@@ -3,27 +3,30 @@ package manners
import (
"bufio"
"crypto/tls"
+ "errors"
"io/ioutil"
"net"
"net/http"
+ "os"
+ "sync"
"testing"
)
+func newServer() *GracefulServer {
+ return NewWithServer(new(http.Server))
+}
+
// a simple step-controllable http client
type client struct {
tls bool
addr net.Addr
connected chan error
sendrequest chan bool
- response chan *rawResponse
+ idle chan error
+ idlerelease chan bool
closed chan bool
}
-type rawResponse struct {
- body []string
- err error
-}
-
func (c *client) Run() {
go func() {
var err error
@@ -39,21 +42,19 @@ func (c *client) Run() {
for <-c.sendrequest {
_, err = conn.Write([]byte("GET / HTTP/1.1\nHost: localhost:8000\n\n"))
if err != nil {
- c.response <- &rawResponse{err: err}
+ c.idle <- err
}
// Read response; no content
scanner := bufio.NewScanner(conn)
- var lines []string
for scanner.Scan() {
// our null handler doesn't send a body, so we know the request is
// done when we reach the blank line after the headers
- line := scanner.Text()
- if line == "" {
+ if scanner.Text() == "" {
break
}
- lines = append(lines, line)
}
- c.response <- &rawResponse{lines, scanner.Err()}
+ c.idle <- scanner.Err()
+ <-c.idlerelease
}
conn.Close()
ioutil.ReadAll(conn)
@@ -67,7 +68,8 @@ func newClient(addr net.Addr, tls bool) *client {
tls: tls,
connected: make(chan error),
sendrequest: make(chan bool),
- response: make(chan *rawResponse),
+ idle: make(chan error),
+ idlerelease: make(chan bool),
closed: make(chan bool),
}
}
@@ -86,6 +88,7 @@ func startGenericServer(t *testing.T, server *GracefulServer, statechanged chan
}
}
+ //server.up = make(chan chan bool))
server.up = make(chan net.Listener)
exitchan := make(chan error)
@@ -117,3 +120,115 @@ func startTLSServer(t *testing.T, server *GracefulServer, certFile, keyFile stri
return startGenericServer(t, server, statechanged, runner)
}
+
+type tempFile struct {
+ *os.File
+}
+
+func newTempFile(content []byte) (*tempFile, error) {
+ f, err := ioutil.TempFile("", "graceful-test")
+ if err != nil {
+ return nil, err
+ }
+
+ f.Write(content)
+ return &tempFile{f}, nil
+}
+
+func (tf *tempFile) Unlink() {
+ if tf.File != nil {
+ os.Remove(tf.Name())
+ tf.File = nil
+ }
+}
+
+type testWg struct {
+ sync.Mutex
+ count int
+ waitCalled chan int
+}
+
+func newTestWg() *testWg {
+ return &testWg{
+ waitCalled: make(chan int, 1),
+ }
+}
+
+func (wg *testWg) Add(delta int) {
+ wg.Lock()
+ wg.count++
+ wg.Unlock()
+}
+
+func (wg *testWg) Done() {
+ wg.Lock()
+ wg.count--
+ wg.Unlock()
+}
+
+func (wg *testWg) Wait() {
+ wg.Lock()
+ wg.waitCalled <- wg.count
+ wg.Unlock()
+}
+
+type fakeConn struct {
+ net.Conn
+ closeCalled bool
+}
+
+func (c *fakeConn) Close() error {
+ c.closeCalled = true
+ return nil
+}
+
+type fakeListener struct {
+ acceptRelease chan bool
+ closeCalled chan bool
+}
+
+func newFakeListener() *fakeListener { return &fakeListener{make(chan bool, 1), make(chan bool, 1)} }
+
+func (l *fakeListener) Addr() net.Addr {
+ addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:8080")
+ return addr
+}
+
+func (l *fakeListener) Close() error {
+ l.closeCalled <- true
+ l.acceptRelease <- true
+ return nil
+}
+
+func (l *fakeListener) Accept() (net.Conn, error) {
+ <-l.acceptRelease
+ return nil, errors.New("connection closed")
+}
+
+// localhostCert is a PEM-encoded TLS cert with SAN IPs
+// "127.0.0.1" and "[::1]", expiring at the last second of 2049 (the end
+// of ASN.1 time).
+// generated from src/pkg/crypto/tls:
+// go run generate_cert.go --rsa-bits 512 --host 127.0.0.1,::1,example.com --ca --start-date "Jan 1 00:00:00 1970" --duration=1000000h
+var (
+ localhostCert = []byte(`-----BEGIN CERTIFICATE-----
+MIIBdzCCASOgAwIBAgIBADALBgkqhkiG9w0BAQUwEjEQMA4GA1UEChMHQWNtZSBD
+bzAeFw03MDAxMDEwMDAwMDBaFw00OTEyMzEyMzU5NTlaMBIxEDAOBgNVBAoTB0Fj
+bWUgQ28wWjALBgkqhkiG9w0BAQEDSwAwSAJBAN55NcYKZeInyTuhcCwFMhDHCmwa
+IUSdtXdcbItRB/yfXGBhiex00IaLXQnSU+QZPRZWYqeTEbFSgihqi1PUDy8CAwEA
+AaNoMGYwDgYDVR0PAQH/BAQDAgCkMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA8GA1Ud
+EwEB/wQFMAMBAf8wLgYDVR0RBCcwJYILZXhhbXBsZS5jb22HBH8AAAGHEAAAAAAA
+AAAAAAAAAAAAAAEwCwYJKoZIhvcNAQEFA0EAAoQn/ytgqpiLcZu9XKbCJsJcvkgk
+Se6AbGXgSlq+ZCEVo0qIwSgeBqmsJxUu7NCSOwVJLYNEBO2DtIxoYVk+MA==
+-----END CERTIFICATE-----`)
+
+ localhostKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
+MIIBPAIBAAJBAN55NcYKZeInyTuhcCwFMhDHCm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