pkg/transport: add NewTimeoutTransport test

release-2.0
Yicheng Qin 2015-01-09 13:42:41 -08:00
parent e688471c28
commit 3577ed69a2
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/*
Copyright 2014 CoreOS, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package transport
import (
"net/http"
"net/http/httptest"
"testing"
"time"
)
// TestNewTimeoutTransport tests that NewTimeoutTransport returns a transport
// that can dial out timeout connections.
func TestNewTimeoutTransport(t *testing.T) {
tr, err := NewTimeoutTransport(TLSInfo{}, time.Hour, time.Hour)
if err != nil {
t.Fatalf("unexpected NewTimeoutTransport error: %v", err)
}
srv := httptest.NewServer(http.NotFoundHandler())
defer srv.Close()
conn, err := tr.Dial("tcp", srv.Listener.Addr().String())
if err != nil {
t.Fatalf("unexpected dial error: %v", err)
}
defer conn.Close()
tconn, ok := conn.(*timeoutConn)
if !ok {
t.Fatalf("failed to dial out *timeoutConn")
}
if tconn.rdtimeoutd != time.Hour {
t.Errorf("read timeout = %s, want %s", tconn.rdtimeoutd, time.Hour)
}
if tconn.wtimeoutd != time.Hour {
t.Errorf("write timeout = %s, want %s", tconn.wtimeoutd, time.Hour)
}
}