forked from GoCodeAlone/modular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdd_config_test.go
More file actions
157 lines (125 loc) · 4.42 KB
/
bdd_config_test.go
File metadata and controls
157 lines (125 loc) · 4.42 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package httpclient
import (
"fmt"
"time"
)
// Configuration and Connection Management BDD Test Steps
func (ctx *HTTPClientBDDTestContext) iHaveAnHTTPClientConfigurationWithConnectionPooling() error {
ctx.resetContext()
// Create httpclient configuration with connection pooling
ctx.clientConfig = &Config{
MaxIdleConns: 200, // Custom pool size
MaxIdleConnsPerHost: 20, // Custom per-host pool size
IdleConnTimeout: 120 * time.Second,
RequestTimeout: 30 * time.Second,
TLSTimeout: 10 * time.Second,
DisableCompression: false,
DisableKeepAlives: false, // Keep-alive enabled for pooling
Verbose: false,
}
return ctx.setupApplicationWithConfig()
}
func (ctx *HTTPClientBDDTestContext) theClientShouldHaveTheConfiguredMaxIdleConnections() error {
if ctx.clientConfig.MaxIdleConns != 200 {
return fmt.Errorf("max idle connections not configured correctly")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) theClientShouldHaveTheConfiguredMaxIdleConnectionsPerHost() error {
if ctx.clientConfig.MaxIdleConnsPerHost != 20 {
return fmt.Errorf("max idle connections per host not configured correctly")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) connectionReuseShouldBeEnabled() error {
if ctx.clientConfig.DisableKeepAlives {
return fmt.Errorf("connection reuse should be enabled but keep-alives are disabled")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) iHaveAnHTTPClientConfigurationWithVerboseLoggingEnabled() error {
ctx.resetContext()
// Create httpclient configuration with verbose logging
ctx.clientConfig = &Config{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
RequestTimeout: 30 * time.Second,
TLSTimeout: 10 * time.Second,
DisableCompression: false,
DisableKeepAlives: false,
Verbose: true, // Enable verbose logging
VerboseOptions: &VerboseOptions{
LogToFile: true,
LogFilePath: "/tmp/httpclient",
},
}
return ctx.setupApplicationWithConfig()
}
func (ctx *HTTPClientBDDTestContext) iMakeHTTPRequests() error {
return ctx.iMakeAGETRequestToATestEndpoint()
}
func (ctx *HTTPClientBDDTestContext) requestAndResponseDetailsShouldBeLogged() error {
if !ctx.clientConfig.Verbose {
return fmt.Errorf("verbose logging not enabled")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) theLogsShouldIncludeHeadersAndTimingInformation() error {
if ctx.clientConfig.VerboseOptions == nil {
return fmt.Errorf("verbose options not configured")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) iHaveAnHTTPClientConfigurationWithCompressionEnabled() error {
ctx.resetContext()
// Create httpclient configuration with compression enabled
ctx.clientConfig = &Config{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
RequestTimeout: 30 * time.Second,
TLSTimeout: 10 * time.Second,
DisableCompression: false, // Compression enabled
DisableKeepAlives: false,
Verbose: false,
}
return ctx.setupApplicationWithConfig()
}
func (ctx *HTTPClientBDDTestContext) iMakeRequestsToEndpointsThatSupportCompression() error {
return ctx.iMakeAGETRequestToATestEndpoint()
}
func (ctx *HTTPClientBDDTestContext) theClientShouldHandleGzipCompression() error {
if ctx.clientConfig.DisableCompression {
return fmt.Errorf("compression should be enabled but is disabled")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) compressedResponsesShouldBeAutomaticallyDecompressed() error {
// For BDD purposes, validate compression handling
return nil
}
func (ctx *HTTPClientBDDTestContext) iHaveAnHTTPClientConfigurationWithKeepAliveDisabled() error {
ctx.resetContext()
// Create httpclient configuration with keep-alive disabled
ctx.clientConfig = &Config{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
RequestTimeout: 30 * time.Second,
TLSTimeout: 10 * time.Second,
DisableCompression: false,
DisableKeepAlives: true, // Keep-alive disabled
Verbose: false,
}
return ctx.setupApplicationWithConfig()
}
func (ctx *HTTPClientBDDTestContext) eachRequestShouldUseANewConnection() error {
if !ctx.clientConfig.DisableKeepAlives {
return fmt.Errorf("keep-alives should be disabled")
}
return nil
}
func (ctx *HTTPClientBDDTestContext) connectionsShouldNotBeReused() error {
return ctx.eachRequestShouldUseANewConnection()
}