MCPcopy Create free account
hub / github.com/aws/smithy-go / TestEncodeContentLength

Function TestEncodeContentLength

encoding/httpbinding/encode_test.go:102–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestEncodeContentLength(t *testing.T) {
103 cases := map[string]struct {
104 headerValue string
105 expected int64
106 wantErr bool
107 }{
108 "valid number": {
109 headerValue: "1024",
110 expected: 1024,
111 },
112 "invalid number": {
113 headerValue: "1024.5",
114 wantErr: true,
115 },
116 "not a number": {
117 headerValue: "NaN",
118 wantErr: true,
119 },
120 }
121
122 for name, tt := range cases {
123 t.Run(name, func(t *testing.T) {
124 encoder, err := NewEncoder("/", "", http.Header{})
125 if err != nil {
126 t.Fatalf("expect no error, got %v", err)
127 }
128
129 encoder.SetHeader("Content-Length").String(tt.headerValue)
130
131 req := &http.Request{URL: &url.URL{}}
132 req, err = encoder.Encode(req)
133 if (err != nil) != tt.wantErr {
134 t.Fatalf("unexpected error value wantErr=%v", tt.wantErr)
135 } else if tt.wantErr {
136 return
137 }
138 if e, a := tt.expected, req.ContentLength; e != a {
139 t.Errorf("expect %v, got %v", e, a)
140 }
141 if v := req.Header.Get("Content-Length"); len(v) > 0 {
142 t.Errorf("expect header not to be set")
143 }
144 })
145 }
146}

Callers

nothing calls this directly

Calls 6

SetHeaderMethod · 0.95
EncodeMethod · 0.95
ErrorfMethod · 0.80
NewEncoderFunction · 0.70
StringMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected