-
Notifications
You must be signed in to change notification settings - Fork 53
/
middleware_headers_test.go
74 lines (64 loc) · 2.07 KB
/
middleware_headers_test.go
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
74
package http_test
import (
"context"
"net/http"
"reflect"
"testing"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
func TestAddHeaderValue(t *testing.T) {
stack := middleware.NewStack("stack", smithyhttp.NewStackRequest)
err := smithyhttp.AddHeaderValue("foo", "fooValue")(stack)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
err = smithyhttp.AddHeaderValue("bar", "firstValue")(stack)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
err = smithyhttp.AddHeaderValue("bar", "secondValue")(stack)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
handler := middleware.DecorateHandler(middleware.HandlerFunc(func(ctx context.Context, input interface{}) (output interface{}, metadata middleware.Metadata, err error) {
req := input.(*smithyhttp.Request)
expect := http.Header{
"Foo": []string{"fooValue"},
"Bar": []string{"firstValue", "secondValue"},
}
if !reflect.DeepEqual(expect, req.Header) {
t.Errorf("%v != %v", expect, req.Header)
}
return output, metadata, err
}), stack)
_, _, err = handler.Handle(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
}
func TestSetHeaderValue(t *testing.T) {
stack := middleware.NewStack("stack", smithyhttp.NewStackRequest)
err := smithyhttp.SetHeaderValue("foo", "firstValue")(stack)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
err = smithyhttp.SetHeaderValue("foo", "secondValue")(stack)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
handler := middleware.DecorateHandler(middleware.HandlerFunc(func(ctx context.Context, input interface{}) (output interface{}, metadata middleware.Metadata, err error) {
req := input.(*smithyhttp.Request)
expect := http.Header{
"Foo": []string{"secondValue"},
}
if !reflect.DeepEqual(expect, req.Header) {
t.Errorf("%v != %v", expect, req.Header)
}
return output, metadata, err
}), stack)
_, _, err = handler.Handle(context.Background(), nil)
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
}