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

Function TestEncoder

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

Source from the content-addressed store, hash-verified

8)
9
10func TestEncoder(t *testing.T) {
11 actual := &http.Request{
12 Header: http.Header{
13 "custom-user-header": {"someValue"},
14 },
15 URL: &url.URL{
16 Path: "/some/{pathKeyOne}/{pathKeyTwo}",
17 RawQuery: "someExistingKeys=foobar",
18 },
19 }
20
21 expected := &http.Request{
22 Header: map[string][]string{
23 "custom-user-header": {"someValue"},
24 "x-amzn-header-foo": {"someValue"},
25 "x-amzn-meta-foo": {"someValue"},
26 },
27 URL: &url.URL{
28 Path: "/some/someValue/path",
29 RawPath: "/some/someValue/path",
30 RawQuery: "someExistingKeys=foobar&someKey=someValue&someKey=otherValue",
31 },
32 }
33
34 encoder, err := NewEncoder(actual.URL.Path, actual.URL.RawQuery, actual.Header)
35 if err != nil {
36 t.Fatalf("expected no error, got %v", err)
37 }
38
39 // Headers
40 encoder.AddHeader("x-amzn-header-foo").String("someValue")
41 encoder.Headers("x-amzn-meta-").AddHeader("foo").String("someValue")
42
43 // Query
44 encoder.SetQuery("someKey").String("someValue")
45 encoder.AddQuery("someKey").String("otherValue")
46
47 // URI
48 if err := encoder.SetURI("pathKeyOne").String("someValue"); err != nil {
49 t.Errorf("expected no err, but got %v", err)
50 }
51
52 // URI
53 if err := encoder.SetURI("pathKeyTwo").String("path"); err != nil {
54 t.Errorf("expected no err, but got %v", err)
55 }
56
57 if actual, err = encoder.Encode(actual); err != nil {
58 t.Errorf("expected no err, but got %v", err)
59 }
60
61 if !reflect.DeepEqual(expected, actual) {
62 t.Errorf("expected %v, but got %v", expected, actual)
63 }
64}
65
66func TestEncoderHasHeader(t *testing.T) {
67 encoder, err := NewEncoder("/", "", http.Header{})

Callers

nothing calls this directly

Calls 10

AddHeaderMethod · 0.95
HeadersMethod · 0.95
SetQueryMethod · 0.95
AddQueryMethod · 0.95
SetURIMethod · 0.95
EncodeMethod · 0.95
ErrorfMethod · 0.80
NewEncoderFunction · 0.70
StringMethod · 0.65
AddHeaderMethod · 0.45

Tested by

no test coverage detected