summaryrefslogtreecommitdiff
path: root/racer_test.go
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-12-08 14:24:03 -0700
committermo khan <mo.khan@gmail.com>2019-12-08 14:24:03 -0700
commit7fce998f980022a2954fd99d3049c422881319e3 (patch)
tree4fc34cedc27f5d319e58c778b93da8d9caf162f1 /racer_test.go
parent4748519fd9cb750de0d1dd22907e4b9af6fb81c2 (diff)
start work on racerHEADmaster
Diffstat (limited to 'racer_test.go')
-rw-r--r--racer_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/racer_test.go b/racer_test.go
new file mode 100644
index 0000000..a9c2b0e
--- /dev/null
+++ b/racer_test.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+ "time"
+)
+
+func TestRacer(t *testing.T) {
+ slowServer := makeDelayedServer(20 * time.Millisecond)
+ fastServer := makeDelayedServer(0 * time.Millisecond)
+
+ defer slowServer.Close()
+ defer fastServer.Close()
+
+ slowUrl := slowServer.URL
+ fastUrl := fastServer.URL
+
+ want := fastUrl
+ got := Racer(slowUrl, fastUrl)
+
+ if got != want {
+ t.Errorf("got %q, want %q", got, want)
+ }
+}
+
+func makeDelayedServer(delay time.Duration) *httptest.Server {
+ return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ time.Sleep(delay)
+ w.WriteHeader(http.StatusOK)
+ }))
+}