...

Source file src/goji.io/dispatch_test.go

Documentation: goji.io

     1  package goji
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"goji.io/internal"
     9  )
    10  
    11  func TestDispatch(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	var d dispatch
    15  
    16  	w, r := wr()
    17  	d.ServeHTTP(w, r)
    18  	if w.Code != 404 {
    19  		t.Errorf("status: expected %d, got %d", 404, w.Code)
    20  	}
    21  
    22  	w, r = wr()
    23  	h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    24  		w.WriteHeader(123)
    25  	})
    26  	ctx := context.WithValue(context.Background(), internal.Handler, h)
    27  	r = r.WithContext(ctx)
    28  	d.ServeHTTP(w, r)
    29  	if w.Code != 123 {
    30  		t.Errorf("status: expected %d, got %d", 123, w.Code)
    31  	}
    32  }
    33  

View as plain text