http2_fallback_transport_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package httpclient
  2. import (
  3. "testing"
  4. )
  5. func TestHTTP2FallbackAuthorityIsolation(t *testing.T) {
  6. transport := &http2FallbackTransport{fallbackAuthority: make(map[string]struct{})}
  7. transport.markH2Fallback("a.example:443")
  8. if !transport.isH2Fallback("a.example:443") {
  9. t.Fatal("a.example:443 should be marked")
  10. }
  11. if transport.isH2Fallback("b.example:443") {
  12. t.Fatal("b.example:443 must remain unmarked after marking a.example")
  13. }
  14. transport.markH2Fallback("b.example:443")
  15. if !transport.isH2Fallback("b.example:443") {
  16. t.Fatal("b.example:443 should be marked after explicit mark")
  17. }
  18. if !transport.isH2Fallback("a.example:443") {
  19. t.Fatal("a.example:443 mark must survive marking another authority")
  20. }
  21. }
  22. func TestHTTP2FallbackEmptyAuthorityNoOp(t *testing.T) {
  23. transport := &http2FallbackTransport{fallbackAuthority: make(map[string]struct{})}
  24. transport.markH2Fallback("")
  25. if len(transport.fallbackAuthority) != 0 {
  26. t.Fatalf("empty authority must not be stored, got %d entries", len(transport.fallbackAuthority))
  27. }
  28. if transport.isH2Fallback("") {
  29. t.Fatal("isH2Fallback must be false for empty authority")
  30. }
  31. }