Skip to content

Commit 5a9b319

Browse files
committed
Remove boolean from parameters
1 parent 4277f74 commit 5a9b319

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

tests/framework/logging.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package framework
2+
3+
type Option func(*Options)
4+
5+
type Options struct {
6+
logEnabled bool
7+
}
8+
9+
func WithLoggingDisabled() Option {
10+
return func(opts *Options) {
11+
opts.logEnabled = false
12+
}
13+
}

tests/framework/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func CreateEndTimeFinder(
458458
// CreateResponseChecker returns a function that checks if there is a successful response from a url.
459459
func CreateResponseChecker(url, address string, requestTimeout time.Duration) func() error {
460460
return func() error {
461-
status, _, err := Get(url, address, requestTimeout, nil, nil, true)
461+
status, _, err := Get(url, address, requestTimeout, nil, nil)
462462
if err != nil {
463463
return fmt.Errorf("bad response: %w", err)
464464
}

tests/framework/request.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ func Get(
2222
url, address string,
2323
timeout time.Duration,
2424
headers, queryParams map[string]string,
25-
logging bool,
25+
opts ...Option,
2626
) (int, string, error) {
27-
resp, err := makeRequest(http.MethodGet, url, address, nil, timeout, headers, queryParams, logging)
27+
options := &Options{logEnabled: true}
28+
for _, opt := range opts {
29+
opt(options)
30+
}
31+
32+
resp, err := makeRequest(http.MethodGet, url, address, nil, timeout, headers, queryParams, opts...)
2833
if err != nil {
29-
if logging {
34+
if options.logEnabled {
3035
GinkgoWriter.Printf(
3136
"ERROR occurred during getting response, error: %s\nReturning status: 0, body: ''\n",
3237
err,
@@ -43,7 +48,7 @@ func Get(
4348
GinkgoWriter.Printf("ERROR in Body content: %v returning body: ''\n", err)
4449
return resp.StatusCode, "", err
4550
}
46-
if logging {
51+
if options.logEnabled {
4752
GinkgoWriter.Printf("Successfully received response and parsed body: %s\n", body.String())
4853
}
4954

@@ -58,7 +63,7 @@ func Post(
5863
timeout time.Duration,
5964
headers, queryParams map[string]string,
6065
) (*http.Response, error) {
61-
response, err := makeRequest(http.MethodPost, url, address, body, timeout, headers, queryParams, true)
66+
response, err := makeRequest(http.MethodPost, url, address, body, timeout, headers, queryParams)
6267
if err != nil {
6368
GinkgoWriter.Printf("ERROR occurred during getting response, error: %s\n", err)
6469
}
@@ -71,7 +76,7 @@ func makeRequest(
7176
body io.Reader,
7277
timeout time.Duration,
7378
headers, queryParams map[string]string,
74-
logging bool,
79+
opts ...Option,
7580
) (*http.Response, error) {
7681
dialer := &net.Dialer{}
7782

@@ -94,7 +99,12 @@ func makeRequest(
9499
ctx, cancel := context.WithTimeout(context.Background(), timeout)
95100
defer cancel()
96101

97-
if logging {
102+
options := &Options{logEnabled: true}
103+
104+
for _, opt := range opts {
105+
opt(options)
106+
}
107+
if options.logEnabled {
98108
requestDetails := fmt.Sprintf(
99109
"Method: %s, URL: %s, Address: %s, Headers: %v, QueryParams: %v\n",
100110
strings.ToUpper(method),

tests/suite/advanced_routing_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ func expectRequestToRespondFromExpectedServer(
117117
headers, queryParams map[string]string,
118118
) error {
119119
GinkgoWriter.Printf("Expecting request to respond from the server %q\n", expServerName)
120-
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, headers, queryParams, true)
120+
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, headers, queryParams)
121121
if err != nil {
122-
GinkgoWriter.Printf("ERROR making GET request to %q: %v\n", appURL, err)
123-
124122
return err
125123
}
126124

tests/suite/graceful_recovery_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ var _ = Describe("Graceful Recovery test", Ordered, FlakeAttempts(2), Label("gra
518518
})
519519

520520
func expectRequestToSucceed(appURL, address string, responseBodyMessage string) error {
521-
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, nil, nil, true)
521+
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, nil, nil)
522522

523523
if status != http.StatusOK {
524524
return fmt.Errorf("http status was not 200, got %d: %w", status, err)
@@ -540,7 +540,7 @@ func expectRequestToSucceed(appURL, address string, responseBodyMessage string)
540540
// We only want an error returned from this particular function if it does not appear that NGINX has
541541
// stopped serving traffic.
542542
func expectRequestToFail(appURL, address string) error {
543-
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, nil, nil, true)
543+
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout, nil, nil)
544544
if status != 0 {
545545
return errors.New("expected http status to be 0")
546546
}

tests/suite/sample_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var _ = Describe("Basic test example", Label("functional"), func() {
6161

6262
Eventually(
6363
func() error {
64-
status, body, err := framework.Get(url, address, timeoutConfig.RequestTimeout, nil, nil, true)
64+
status, body, err := framework.Get(url, address, timeoutConfig.RequestTimeout, nil, nil)
6565
if err != nil {
6666
return err
6767
}

tests/suite/tracing_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ var _ = Describe("Tracing", FlakeAttempts(2), Ordered, Label("functional", "trac
131131
for range count {
132132
Eventually(
133133
func() error {
134-
status, _, err := framework.Get(url, address, timeoutConfig.RequestTimeout, nil, nil, false)
134+
status, _, err := framework.Get(
135+
url,
136+
address,
137+
timeoutConfig.RequestTimeout,
138+
nil,
139+
nil,
140+
framework.WithLoggingDisabled(),
141+
)
135142
if err != nil {
136143
return err
137144
}

0 commit comments

Comments
 (0)