File: client_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.49.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312,636 kB
  • sloc: makefile: 120
file content (80 lines) | stat: -rw-r--r-- 1,918 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
package client

import (
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/client/metadata"
	"github.com/aws/aws-sdk-go/aws/request"
)

func pushBackTestHandler(name string, list *request.HandlerList) *bool {
	called := false
	(*list).PushBackNamed(request.NamedHandler{
		Name: name,
		Fn: func(r *request.Request) {
			called = true
		},
	})

	return &called
}

func pushFrontTestHandler(name string, list *request.HandlerList) *bool {
	called := false
	(*list).PushFrontNamed(request.NamedHandler{
		Name: name,
		Fn: func(r *request.Request) {
			called = true
		},
	})

	return &called
}

func TestNewClient_CopyHandlers(t *testing.T) {
	handlers := request.Handlers{}
	firstCalled := pushBackTestHandler("first", &handlers.Send)
	secondCalled := pushBackTestHandler("second", &handlers.Send)

	var clientHandlerCalled *bool
	c := New(aws.Config{}, metadata.ClientInfo{}, handlers,
		func(c *Client) {
			clientHandlerCalled = pushFrontTestHandler("client handler", &c.Handlers.Send)
		},
	)

	if e, a := 2, handlers.Send.Len(); e != a {
		t.Errorf("expect %d original handlers, got %d", e, a)
	}
	if e, a := 5, c.Handlers.Send.Len(); e != a {
		t.Errorf("expect %d client handlers, got %d", e, a)
	}

	req := c.NewRequest(&request.Operation{}, struct{}{}, struct{}{})

	handlers.Send.Run(req)
	if !*firstCalled {
		t.Errorf("expect first handler to of been called")
	}
	*firstCalled = false
	if !*secondCalled {
		t.Errorf("expect second handler to of been called")
	}
	*secondCalled = false
	if *clientHandlerCalled {
		t.Errorf("expect client handler to not of been called, but was")
	}

	c.Handlers.Send.Run(req)
	if !*firstCalled {
		t.Errorf("expect client's first handler to of been called")
	}
	if !*secondCalled {
		t.Errorf("expect client's second handler to of been called")
	}
	if !*clientHandlerCalled {
		t.Errorf("expect client's client handler to of been called")
	}

}