racer: test with httptest server

This commit is contained in:
vinchent 2024-09-18 12:45:58 +02:00
parent 491d2c1b22
commit 3538818769

View File

@ -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)