-
Notifications
You must be signed in to change notification settings - Fork 14
/
kiota_client_factory_test.go
99 lines (90 loc) · 2.64 KB
/
kiota_client_factory_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package nethttplibrary
import (
abstractions "github.com/microsoft/kiota-abstractions-go"
"github.com/stretchr/testify/assert"
nethttp "net/http"
"testing"
"time"
)
func TestGetDefaultMiddleWareWithMultipleOptions(t *testing.T) {
retryOptions := RetryHandlerOptions{
ShouldRetry: func(delay time.Duration, executionCount int, request *nethttp.Request, response *nethttp.Response) bool {
return false
},
}
redirectHandlerOptions := RedirectHandlerOptions{
MaxRedirects: defaultMaxRedirects,
ShouldRedirect: func(req *nethttp.Request, res *nethttp.Response) bool {
return true
},
}
compressionOptions := NewCompressionOptions(false)
parametersNameDecodingOptions := ParametersNameDecodingOptions{
Enable: true,
ParametersToDecode: []byte{'-', '.', '~', '$'},
}
userAgentHandlerOptions := UserAgentHandlerOptions{
Enabled: true,
ProductName: "kiota-go",
ProductVersion: "1.1.0",
}
headersInspectionOptions := HeadersInspectionOptions{
RequestHeaders: abstractions.NewRequestHeaders(),
ResponseHeaders: abstractions.NewResponseHeaders(),
}
options, err := GetDefaultMiddlewaresWithOptions(&retryOptions,
&redirectHandlerOptions,
&compressionOptions,
¶metersNameDecodingOptions,
&userAgentHandlerOptions,
&headersInspectionOptions,
)
if err != nil {
t.Errorf(err.Error())
}
if len(options) != 6 {
t.Errorf("expected 6 middleware, got %v", len(options))
}
for _, element := range options {
switch v := element.(type) {
case *CompressionHandler:
assert.Equal(t, v.options.ShouldCompress(), compressionOptions.ShouldCompress())
}
}
}
func TestGetDefaultMiddleWareWithInvalidOption(t *testing.T) {
chaosOptions := ChaosHandlerOptions{
ChaosPercentage: 101,
ChaosStrategy: Random,
}
_, err := GetDefaultMiddlewaresWithOptions(&chaosOptions)
assert.Equal(t, err.Error(), "unsupported option type")
}
func TestGetDefaultMiddleWareWithOptions(t *testing.T) {
compression := NewCompressionOptions(false)
options, err := GetDefaultMiddlewaresWithOptions(&compression)
if err != nil {
t.Errorf(err.Error())
}
if len(options) != 6 {
t.Errorf("expected 6 middleware, got %v", len(options))
}
for _, element := range options {
switch v := element.(type) {
case *CompressionHandler:
assert.Equal(t, v.options.ShouldCompress(), compression.ShouldCompress())
}
}
}
func TestGetDefaultMiddlewares(t *testing.T) {
options := GetDefaultMiddlewares()
if len(options) != 6 {
t.Errorf("expected 6 middleware, got %v", len(options))
}
for _, element := range options {
switch v := element.(type) {
case *CompressionHandler:
assert.True(t, v.options.ShouldCompress())
}
}
}