github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/server/server_test.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	"github.com/docker/docker/api/server/httputils"
     9  
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  func TestMiddlewares(t *testing.T) {
    14  	cfg := &Config{}
    15  	srv := &Server{
    16  		cfg: cfg,
    17  	}
    18  
    19  	req, _ := http.NewRequest("GET", "/containers/json", nil)
    20  	resp := httptest.NewRecorder()
    21  	ctx := context.Background()
    22  
    23  	localHandler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    24  		if httputils.VersionFromContext(ctx) == "" {
    25  			t.Fatalf("Expected version, got empty string")
    26  		}
    27  		return nil
    28  	}
    29  
    30  	handlerFunc := srv.handleWithGlobalMiddlewares(localHandler)
    31  	if err := handlerFunc(ctx, resp, req, map[string]string{}); err != nil {
    32  		t.Fatal(err)
    33  	}
    34  }