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.
 
 
 

57 lines
1.6 KiB

  1. // Copyright 2016 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 api
  15. import (
  16. "net/http"
  17. "testing"
  18. "github.com/google/martian"
  19. )
  20. func TestApiForwarder(t *testing.T) {
  21. forwarder := NewForwarder("", 8181)
  22. req, err := http.NewRequest("GET", "https://martian.proxy/configure", nil)
  23. if err != nil {
  24. t.Fatalf("NewRequest(): got %v, want no error", err)
  25. }
  26. ctx, remove, err := martian.TestContext(req, nil, nil)
  27. if err != nil {
  28. t.Fatalf("TestContext(): got %v, want no error", err)
  29. }
  30. defer remove()
  31. if err := forwarder.ModifyRequest(req); err != nil {
  32. t.Fatalf("ModifyRequest(): got %v, want no error", err)
  33. }
  34. if got, want := req.URL.Scheme, "http"; got != want {
  35. t.Errorf("req.URL.Scheme: got %s, want %s", got, want)
  36. }
  37. if got, want := req.URL.Host, "localhost:8181"; got != want {
  38. t.Errorf("req.URL.Host: got %s, want %s", got, want)
  39. }
  40. if !ctx.SkippingLogging() {
  41. t.Errorf("ctx.SkippingLogging: got false, want true")
  42. }
  43. if !ctx.IsAPIRequest() {
  44. t.Errorf("ctx.IsApiRequest: got false, want true")
  45. }
  46. }