You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.7 KiB

  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package martian
  15. import (
  16. "net/http"
  17. "testing"
  18. "github.com/google/martian/proxyutil"
  19. )
  20. func TestModifierFuncs(t *testing.T) {
  21. reqmod := RequestModifierFunc(
  22. func(req *http.Request) error {
  23. req.Header.Set("Request-Modified", "true")
  24. return nil
  25. })
  26. resmod := ResponseModifierFunc(
  27. func(res *http.Response) error {
  28. res.Header.Set("Response-Modified", "true")
  29. return nil
  30. })
  31. req, err := http.NewRequest("GET", "http://example.com", nil)
  32. if err != nil {
  33. t.Fatalf("http.NewRequest(): got %v, want no error", err)
  34. }
  35. if err := reqmod.ModifyRequest(req); err != nil {
  36. t.Fatalf("reqmod.ModifyRequest(): got %v, want no error", err)
  37. }
  38. if got, want := req.Header.Get("Request-Modified"), "true"; got != want {
  39. t.Errorf("req.Header.Get(%q): got %q, want %q", "Request-Modified", got, want)
  40. }
  41. res := proxyutil.NewResponse(200, nil, req)
  42. if err := resmod.ModifyResponse(res); err != nil {
  43. t.Fatalf("resmod.ModifyResponse(): got %v, want no error", err)
  44. }
  45. if got, want := res.Header.Get("Response-Modified"), "true"; got != want {
  46. t.Errorf("res.Header.Get(%q): got %q, want %q", "Response-Modified", got, want)
  47. }
  48. }