racer: test with httptest server
This commit is contained in:
parent
491d2c1b22
commit
3538818769
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user