github.com/soulinfo/etcd@v0.1.2-0.20130922053317-3a0a8c89e859/transporter_test.go (about)

     1  package main
     2  
     3  import (
     4  	"crypto/tls"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestTransporterTimeout(t *testing.T) {
    10  
    11  	conf := tls.Config{}
    12  
    13  	ts := newTransporter("http", conf, time.Second)
    14  
    15  	ts.Get("http://google.com")
    16  	_, err := ts.Get("http://google.com:9999") // it doesn't exisit
    17  	if err == nil || err.Error() != "Wait Response Timeout: 1s" {
    18  		t.Fatal("timeout error: ", err.Error())
    19  	}
    20  
    21  	_, err = ts.Post("http://google.com:9999", nil) // it doesn't exisit
    22  	if err == nil || err.Error() != "Wait Response Timeout: 1s" {
    23  		t.Fatal("timeout error: ", err.Error())
    24  	}
    25  
    26  	_, err = ts.Get("http://www.google.com")
    27  	if err != nil {
    28  		t.Fatal("get error")
    29  	}
    30  
    31  	_, err = ts.Post("http://www.google.com", nil)
    32  	if err != nil {
    33  		t.Fatal("post error")
    34  	}
    35  
    36  }