Add TestDial
This commit is contained in:
parent
1d2b6deeef
commit
2379baeb24
|
@ -66,6 +66,7 @@ func TestStreamingWSUser(t *testing.T) {
|
||||||
|
|
||||||
wsTest(t, q, cancel)
|
wsTest(t, q, cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStreamingWSHashtag(t *testing.T) {
|
func TestStreamingWSHashtag(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(wsMock))
|
ts := httptest.NewServer(http.HandlerFunc(wsMock))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
@ -84,6 +85,7 @@ func TestStreamingWSHashtag(t *testing.T) {
|
||||||
|
|
||||||
wsTest(t, q, cancel)
|
wsTest(t, q, cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStreamingWSHashtagLocal(t *testing.T) {
|
func TestStreamingWSHashtagLocal(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(wsMock))
|
ts := httptest.NewServer(http.HandlerFunc(wsMock))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
@ -154,6 +156,39 @@ func wsTest(t *testing.T, q chan Event, cancel func()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDial(t *testing.T) {
|
||||||
|
canErr := true
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if canErr {
|
||||||
|
canErr = false
|
||||||
|
http.Redirect(w, r, ":", http.StatusMovedPermanently)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "http://www.example.com/", http.StatusMovedPermanently)
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{})
|
||||||
|
_, _, err := client.dial(":")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, rawurl, err := client.dial("ws://" + ts.Listener.Addr().String())
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, rawurl, err = client.dial("ws://" + ts.Listener.Addr().String())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if rawurl != "ws://www.example.com/" {
|
||||||
|
t.Fatalf("want %q but %q", "ws://www.example.com/", rawurl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestChangeWebSocketScheme(t *testing.T) {
|
func TestChangeWebSocketScheme(t *testing.T) {
|
||||||
_, err := changeWebSocketScheme(":")
|
_, err := changeWebSocketScheme(":")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user