OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / net / http2 / go18_test.go
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
5 // +build go1.8
6
7 package http2
8
9 import (
10         "crypto/tls"
11         "net/http"
12         "testing"
13         "time"
14 )
15
16 // Tests that http2.Server.IdleTimeout is initialized from
17 // http.Server.{Idle,Read}Timeout. http.Server.IdleTimeout was
18 // added in Go 1.8.
19 func TestConfigureServerIdleTimeout_Go18(t *testing.T) {
20         const timeout = 5 * time.Second
21         const notThisOne = 1 * time.Second
22
23         // With a zero http2.Server, verify that it copies IdleTimeout:
24         {
25                 s1 := &http.Server{
26                         IdleTimeout: timeout,
27                         ReadTimeout: notThisOne,
28                 }
29                 s2 := &Server{}
30                 if err := ConfigureServer(s1, s2); err != nil {
31                         t.Fatal(err)
32                 }
33                 if s2.IdleTimeout != timeout {
34                         t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
35                 }
36         }
37
38         // And that it falls back to ReadTimeout:
39         {
40                 s1 := &http.Server{
41                         ReadTimeout: timeout,
42                 }
43                 s2 := &Server{}
44                 if err := ConfigureServer(s1, s2); err != nil {
45                         t.Fatal(err)
46                 }
47                 if s2.IdleTimeout != timeout {
48                         t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
49                 }
50         }
51
52         // Verify that s1's IdleTimeout doesn't overwrite an existing setting:
53         {
54                 s1 := &http.Server{
55                         IdleTimeout: notThisOne,
56                 }
57                 s2 := &Server{
58                         IdleTimeout: timeout,
59                 }
60                 if err := ConfigureServer(s1, s2); err != nil {
61                         t.Fatal(err)
62                 }
63                 if s2.IdleTimeout != timeout {
64                         t.Errorf("s2.IdleTimeout = %v; want %v", s2.IdleTimeout, timeout)
65                 }
66         }
67 }
68
69 func TestCertClone(t *testing.T) {
70         c := &tls.Config{
71                 GetClientCertificate: func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
72                         panic("shouldn't be called")
73                 },
74         }
75         c2 := cloneTLSConfig(c)
76         if c2.GetClientCertificate == nil {
77                 t.Error("GetClientCertificate is nil")
78         }
79 }