racer: test with httptest server
This commit is contained in:
parent
491d2c1b22
commit
3538818769
@ -1,10 +1,28 @@
|
|||||||
package racer
|
package racer
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func TestRacer(t *testing.T) {
|
func TestRacer(t *testing.T) {
|
||||||
slowURL := "http://www.facebook.com"
|
slowServer := httptest.NewServer(http.HandlerFunc(
|
||||||
fastURL := "http://www.quii.dev"
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
time.Sleep(20 * time.Millisecond)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}))
|
||||||
|
defer slowServer.Close()
|
||||||
|
|
||||||
|
fastServer := httptest.NewServer(http.HandlerFunc(
|
||||||
|
func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}))
|
||||||
|
defer fastServer.Close()
|
||||||
|
|
||||||
|
slowURL := slowServer.URL
|
||||||
|
fastURL := fastServer.URL
|
||||||
|
|
||||||
want := fastURL
|
want := fastURL
|
||||||
got := Racer(slowURL, fastURL)
|
got := Racer(slowURL, fastURL)
|
||||||
|
Loading…
Reference in New Issue
Block a user