server_test.go 773 B

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