frontend: fix unit tests

This commit is contained in:
Lan Tian
2023-11-25 10:47:37 -08:00
parent d261c22235
commit 38bf6aba09
3 changed files with 10 additions and 3156 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -8,6 +8,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/jarcoal/httpmock"
) )
type channelData struct { type channelData struct {
@@ -19,6 +21,12 @@ func createConnectionTimeoutRoundTripper(timeout int) http.RoundTripper {
context := net.Dialer{ context := net.Dialer{
Timeout: time.Duration(timeout) * time.Second, Timeout: time.Duration(timeout) * time.Second,
} }
// Prefer httpmock's transport if activated, so unit tests can work
if http.DefaultTransport == httpmock.DefaultTransport {
return httpmock.DefaultTransport
}
return &http.Transport{ return &http.Transport{
DialContext: context.DialContext, DialContext: context.DialContext,
@@ -67,7 +75,8 @@ func batchRequest(servers []string, endpoint string, command string) []string {
go func(url string, i int) { go func(url string, i int) {
client := http.Client{ client := http.Client{
Transport: createConnectionTimeoutRoundTripper(setting.connectionTimeOut), Transport: createConnectionTimeoutRoundTripper(setting.connectionTimeOut),
Timeout: time.Duration(setting.timeOut) * time.Second} Timeout: time.Duration(setting.timeOut) * time.Second,
}
response, err := client.Get(url) response, err := client.Get(url)
if err != nil { if err != nil {
ch <- channelData{i, "request failed: " + err.Error() + "\n"} ch <- channelData{i, "request failed: " + err.Error() + "\n"}

File diff suppressed because it is too large Load Diff