github.com/aavshr/aws-sdk-go@v1.41.3/aws/client/client_test.go (about) 1 package client 2 3 import ( 4 "testing" 5 6 "github.com/aavshr/aws-sdk-go/aws" 7 "github.com/aavshr/aws-sdk-go/aws/client/metadata" 8 "github.com/aavshr/aws-sdk-go/aws/request" 9 ) 10 11 func pushBackTestHandler(name string, list *request.HandlerList) *bool { 12 called := false 13 (*list).PushBackNamed(request.NamedHandler{ 14 Name: name, 15 Fn: func(r *request.Request) { 16 called = true 17 }, 18 }) 19 20 return &called 21 } 22 23 func pushFrontTestHandler(name string, list *request.HandlerList) *bool { 24 called := false 25 (*list).PushFrontNamed(request.NamedHandler{ 26 Name: name, 27 Fn: func(r *request.Request) { 28 called = true 29 }, 30 }) 31 32 return &called 33 } 34 35 func TestNewClient_CopyHandlers(t *testing.T) { 36 handlers := request.Handlers{} 37 firstCalled := pushBackTestHandler("first", &handlers.Send) 38 secondCalled := pushBackTestHandler("second", &handlers.Send) 39 40 var clientHandlerCalled *bool 41 c := New(aws.Config{}, metadata.ClientInfo{}, handlers, 42 func(c *Client) { 43 clientHandlerCalled = pushFrontTestHandler("client handler", &c.Handlers.Send) 44 }, 45 ) 46 47 if e, a := 2, handlers.Send.Len(); e != a { 48 t.Errorf("expect %d original handlers, got %d", e, a) 49 } 50 if e, a := 5, c.Handlers.Send.Len(); e != a { 51 t.Errorf("expect %d client handlers, got %d", e, a) 52 } 53 54 req := c.NewRequest(&request.Operation{}, struct{}{}, struct{}{}) 55 56 handlers.Send.Run(req) 57 if !*firstCalled { 58 t.Errorf("expect first handler to of been called") 59 } 60 *firstCalled = false 61 if !*secondCalled { 62 t.Errorf("expect second handler to of been called") 63 } 64 *secondCalled = false 65 if *clientHandlerCalled { 66 t.Errorf("expect client handler to not of been called, but was") 67 } 68 69 c.Handlers.Send.Run(req) 70 if !*firstCalled { 71 t.Errorf("expect client's first handler to of been called") 72 } 73 if !*secondCalled { 74 t.Errorf("expect client's second handler to of been called") 75 } 76 if !*clientHandlerCalled { 77 t.Errorf("expect client's client handler to of been called") 78 } 79 80 }