github.com/aavshr/aws-sdk-go@v1.41.3/private/protocol/protocol_go1.7_test.go (about) 1 //go:build go1.7 2 // +build go1.7 3 4 package protocol 5 6 import ( 7 "net/http" 8 "strings" 9 "testing" 10 11 "github.com/aavshr/aws-sdk-go/aws/awserr" 12 "github.com/aavshr/aws-sdk-go/aws/request" 13 ) 14 15 func TestRequireHTTPMinProtocol(t *testing.T) { 16 cases := map[string]struct { 17 Major, Minor int 18 Response *http.Response 19 Err string 20 }{ 21 "HTTP/2.0": { 22 Major: 2, 23 Response: &http.Response{ 24 StatusCode: 200, 25 Proto: "HTTP/2.0", 26 ProtoMajor: 2, ProtoMinor: 0, 27 }, 28 }, 29 "HTTP/1.1": { 30 Major: 2, 31 Response: &http.Response{ 32 StatusCode: 200, 33 Proto: "HTTP/1.1", 34 ProtoMajor: 1, ProtoMinor: 1, 35 }, 36 Err: "operation requires minimum HTTP protocol", 37 }, 38 } 39 40 for name, c := range cases { 41 t.Run(name, func(t *testing.T) { 42 req := &request.Request{ 43 HTTPResponse: c.Response, 44 } 45 RequireHTTPMinProtocol{Major: c.Major, Minor: c.Minor}.Handler(req) 46 47 if len(c.Err) != 0 { 48 if req.Error == nil { 49 t.Fatalf("expect error") 50 } 51 if e, a := c.Err, req.Error.Error(); !strings.Contains(a, e) { 52 t.Errorf("expect %q error, got %q", e, a) 53 } 54 aerr, ok := req.Error.(awserr.RequestFailure) 55 if !ok { 56 t.Fatalf("expect RequestFailure, got %T", req.Error) 57 } 58 59 if e, a := ErrCodeMinimumHTTPProtocolError, aerr.Code(); e != a { 60 t.Errorf("expect %v code, got %v", e, a) 61 } 62 if e, a := c.Response.StatusCode, aerr.StatusCode(); e != a { 63 t.Errorf("expect %v status code, got %v", e, a) 64 } 65 66 } else { 67 if err := req.Error; err != nil { 68 t.Fatalf("expect no failure, got %v", err) 69 } 70 } 71 }) 72 } 73 }