fix(api): Correctly apply BOUNDARY_MAX_RETRIES env var (#5385)
The api.Client was first checking for the environment variable, and then resetting the max retries to 2, thus overriding the environment variable value. In addition, the cli would set max retries to zero if the environment variable was not set. This would mean that by default the max retries would be zero, and if the environment variable was set, the max retries would be 2, regardless of the actual value for the environment variable. This fixes the order in which the environment variables are read, to ensure they take precedence.
This commit is contained in:
1 parent
02fe1b42d3
commit
5329f926b6
4 files changed
+102
-6
No files matched your search
@@ -4,11 +4,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -157,3 +163,86 @@ func TestReadEnvironmentMaxRetries(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
envvars map[string]string
|
||||
want *Config
|
||||
}{
|
||||
{
|
||||
name: "noEnvVarsSet",
|
||||
envvars: nil,
|
||||
want: &Config{
|
||||
Addr: "http://127.0.0.1:9200",
|
||||
Token: "",
|
||||
RecoveryKmsWrapper: nil,
|
||||
HttpClient: func() *http.Client {
|
||||
client := cleanhttp.DefaultPooledClient()
|
||||
client.Transport.(*http.Transport).TLSClientConfig = &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
}
|
||||
return client
|
||||
}(),
|
||||
TLSConfig: &TLSConfig{},
|
||||
Headers: map[string][]string{},
|
||||
MaxRetries: 2,
|
||||
Timeout: time.Second * 60,
|
||||
Backoff: RateLimitLinearJitterBackoff,
|
||||
CheckRetry: nil,
|
||||
Limiter: nil,
|
||||
OutputCurlString: false,
|
||||
SRVLookup: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "maxRetries",
|
||||
envvars: map[string]string{
|
||||
"BOUNDARY_MAX_RETRIES": "5",
|
||||
},
|
||||
want: &Config{
|
||||
Addr: "http://127.0.0.1:9200",
|
||||
Token: "",
|
||||
RecoveryKmsWrapper: nil,
|
||||
HttpClient: func() *http.Client {
|
||||
client := cleanhttp.DefaultPooledClient()
|
||||
client.Transport.(*http.Transport).TLSClientConfig = &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
}
|
||||
return client
|
||||
}(),
|
||||
TLSConfig: &TLSConfig{},
|
||||
Headers: map[string][]string{},
|
||||
MaxRetries: 5,
|
||||
Timeout: time.Second * 60,
|
||||
Backoff: RateLimitLinearJitterBackoff,
|
||||
CheckRetry: nil,
|
||||
Limiter: nil,
|
||||
OutputCurlString: false,
|
||||
SRVLookup: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
for k, v := range tt.envvars {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
for k := range tt.envvars {
|
||||
os.Unsetenv(k)
|
||||
}
|
||||
})
|
||||
|
||||
c, err := DefaultConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Empty(t,
|
||||
cmp.Diff(tt.want, c,
|
||||
cmpopts.IgnoreUnexported(http.Transport{}, tls.Config{}),
|
||||
// Ignore fields that are functions, since cmp.Diff can't
|
||||
// correctly compare them if they are non-nil.
|
||||
cmpopts.IgnoreFields(Config{}, "Backoff"),
|
||||
cmpopts.IgnoreFields(http.Transport{}, "Proxy", "DialContext"),
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user