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