server_test.go 749 B

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