diff --git a/racer/racer_test.go b/racer/racer_test.go index 691bfb0..07f29c7 100644 --- a/racer/racer_test.go +++ b/racer/racer_test.go @@ -1,10 +1,28 @@ package racer -import "testing" +import ( + "net/http" + "net/http/httptest" + "testing" + "time" +) func TestRacer(t *testing.T) { - slowURL := "http://www.facebook.com" - fastURL := "http://www.quii.dev" + slowServer := httptest.NewServer(http.HandlerFunc( + 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 got := Racer(slowURL, fastURL)