go18_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build go1.8
  5. package http2
  6. import (
  7. "crypto/tls"
  8. "net/http"
  9. "testing"
  10. "time"
  11. )
  12. // Tests that http2.Server.IdleTimeout is initialized from
  13. // http.Server.{Idle,Read}Timeout. http.Server.IdleTimeout was
  14. // added in Go 1.8.
  15. func TestConfigureServerIdleTimeout_Go18(t *testing.T) {
  16. const timeout = 5 * time.Second
  17. const notThisOne = 1 * time.Second
  18. // With a zero http2.Server, verify that it copies IdleTimeout:
  19. {
  20. s1 := &http.Server{
  21. IdleTimeout: timeout,
  22. ReadTimeout: notThisOne,
  23. }
  24. s2 := &Server{}
  25. if err := ConfigureServer(s1, s2); err != nil {
  26. t.Fatal(err)
  27. }
  28. if s2.IdleTimeout != timeout {
  29. t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
  30. }
  31. }
  32. // And that it falls back to ReadTimeout:
  33. {
  34. s1 := &http.Server{
  35. ReadTimeout: timeout,
  36. }
  37. s2 := &Server{}
  38. if err := ConfigureServer(s1, s2); err != nil {
  39. t.Fatal(err)
  40. }
  41. if s2.IdleTimeout != timeout {
  42. t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
  43. }
  44. }
  45. // Verify that s1's IdleTimeout doesn't overwrite an existing setting:
  46. {
  47. s1 := &http.Server{
  48. IdleTimeout: notThisOne,
  49. }
  50. s2 := &Server{
  51. IdleTimeout: timeout,
  52. }
  53. if err := ConfigureServer(s1, s2); err != nil {
  54. t.Fatal(err)
  55. }
  56. if s2.IdleTimeout != timeout {
  57. t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
  58. }
  59. }
  60. }
  61. func TestCertClone(t *testing.T) {
  62. c := &tls.Config{
  63. GetClientCertificate: func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
  64. panic("shouldn't be called")
  65. },
  66. }
  67. c2 := cloneTLSConfig(c)
  68. if c2.GetClientCertificate == nil {
  69. t.Error("GetClientCertificate is nil")
  70. }
  71. }