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.
 
 
 

66 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 skip
  15. import (
  16. "net/http"
  17. "testing"
  18. "github.com/google/martian"
  19. "github.com/google/martian/parse"
  20. )
  21. func TestRoundTrip(t *testing.T) {
  22. m := NewRoundTrip()
  23. req, err := http.NewRequest("GET", "http://example.com", nil)
  24. if err != nil {
  25. t.Fatalf("http.NewRequest(): got %v, want no error", err)
  26. }
  27. ctx, remove, err := martian.TestContext(req, nil, nil)
  28. if err != nil {
  29. t.Fatalf("martian.TestContext(): got %v, want no error", err)
  30. }
  31. defer remove()
  32. if ctx.SkippingRoundTrip() {
  33. t.Fatal("ctx.SkippingRoundTrip(): got true, want false")
  34. }
  35. if err := m.ModifyRequest(req); err != nil {
  36. t.Fatalf("ModifyRequest(): got %v, want no error", err)
  37. }
  38. if !ctx.SkippingRoundTrip() {
  39. t.Fatal("ctx.SkippingRoundTrip(): got false, want true")
  40. }
  41. }
  42. func TestFromJSON(t *testing.T) {
  43. msg := []byte(`{
  44. "skip.RoundTrip": {}
  45. }`)
  46. r, err := parse.FromJSON(msg)
  47. if err != nil {
  48. t.Fatalf("parse.FromJSON(): got %v, want no error", err)
  49. }
  50. reqmod := r.RequestModifier()
  51. if _, ok := reqmod.(*RoundTrip); !ok {
  52. t.Fatal("reqmod.(*RoundTrip): got !ok, want ok")
  53. }
  54. }