diff --git a/internal/tun2/server_test.go b/internal/tun2/server_test.go index 00a3464..406d517 100644 --- a/internal/tun2/server_test.go +++ b/internal/tun2/server_test.go @@ -174,21 +174,29 @@ func TestBackendRouting(t *testing.T) { if err != nil { t.Fatal(err) } + defer l.Close() go s.Listen(l, false) cases := []struct { - name string - should200 bool - handler http.HandlerFunc + name string + wantStatusCode int + handler http.HandlerFunc }{ { - name: "200 everything's okay", - should200: true, + name: "200 everything's okay", + wantStatusCode: http.StatusOK, handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.Error(w, "HTTP 200, everything is okay :)", http.StatusOK) }), }, + { + name: "500 internal error", + wantStatusCode: http.StatusInternalServerError, + handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "HTTP 500, the world is on fire", http.StatusInternalServerError) + }), + }, } for _, cs := range cases { @@ -213,7 +221,7 @@ func TestBackendRouting(t *testing.T) { go c.Connect(ctx) // TODO: fix the client library so this ends up actually getting cleaned up - time.Sleep(time.Second) + time.Sleep(125 * time.Millisecond) req, err := http.NewRequest("GET", "http://cetacean.club/", nil) if err != nil { @@ -225,9 +233,9 @@ func TestBackendRouting(t *testing.T) { t.Fatalf("error in doing round trip: %v", err) } - if cs.should200 && resp.StatusCode != http.StatusOK { + if cs.wantStatusCode != resp.StatusCode { resp.Write(os.Stdout) - t.Fatalf("got status %d instead of StatusOK", resp.StatusCode) + t.Fatalf("got status %d instead of %d", resp.StatusCode, cs.wantStatusCode) } }) } @@ -258,8 +266,6 @@ func setupTestServer() (*Server, *mockStorage, net.Listener, error) { } func BenchmarkHTTP200(b *testing.B) { - b.Skip("this benchmark doesn't work yet") - ctx, cancel := context.WithCancel(context.Background()) defer cancel()