racer: add a first racer test

This commit is contained in:
vinchent 2024-09-18 10:15:53 +02:00
parent d83f1c6f4c
commit 491d2c1b22
2 changed files with 38 additions and 0 deletions

23
racer/racer.go Normal file
View File

@ -0,0 +1,23 @@
package racer
import (
"fmt"
"net/http"
"time"
)
func Racer(a, b string) string {
startA := time.Now()
http.Get(a)
aDuration := time.Since(startA)
fmt.Println(aDuration)
startB := time.Now()
http.Get(b)
bDuration := time.Since(startB)
fmt.Println(bDuration)
if aDuration < bDuration {
return a
}
return b
}

15
racer/racer_test.go Normal file
View File

@ -0,0 +1,15 @@
package racer
import "testing"
func TestRacer(t *testing.T) {
slowURL := "http://www.facebook.com"
fastURL := "http://www.quii.dev"
want := fastURL
got := Racer(slowURL, fastURL)
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}