mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-12 04:31:46 +00:00
Merge pull request #117422 from cbandy/client-go-testing-setenv
Replace os.Setenv with testing.T.Setenv in tests Kubernetes-commit: 940101e07e1fbf45747ef67bca43b645b2a67065
This commit is contained in:
commit
bbdc95deee
4
go.mod
4
go.mod
@ -23,7 +23,7 @@ require (
|
|||||||
golang.org/x/term v0.7.0
|
golang.org/x/term v0.7.0
|
||||||
golang.org/x/time v0.3.0
|
golang.org/x/time v0.3.0
|
||||||
google.golang.org/protobuf v1.30.0
|
google.golang.org/protobuf v1.30.0
|
||||||
k8s.io/api v0.0.0-20230503175223-77aab51479c3
|
k8s.io/api v0.0.0-20230503175224-7a87286591e4
|
||||||
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e
|
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e
|
||||||
k8s.io/klog/v2 v2.100.1
|
k8s.io/klog/v2 v2.100.1
|
||||||
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
|
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
|
||||||
@ -59,6 +59,6 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
k8s.io/api => k8s.io/api v0.0.0-20230503175223-77aab51479c3
|
k8s.io/api => k8s.io/api v0.0.0-20230503175224-7a87286591e4
|
||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e
|
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -478,8 +478,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
k8s.io/api v0.0.0-20230503175223-77aab51479c3 h1:VAGMARadnBVFTTRgO/VVDetZxPPjbx9unjDPqZwdw68=
|
k8s.io/api v0.0.0-20230503175224-7a87286591e4 h1:cxVILqCCBsq5MCwFs3RkBL8HDUwZ6Sh5qH0UBJSTnnw=
|
||||||
k8s.io/api v0.0.0-20230503175223-77aab51479c3/go.mod h1:/fu24lnfAhrloAI7EhcGTa0fXXQH5r4rUqEQMW9endY=
|
k8s.io/api v0.0.0-20230503175224-7a87286591e4/go.mod h1:/fu24lnfAhrloAI7EhcGTa0fXXQH5r4rUqEQMW9endY=
|
||||||
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e h1:zTmKa/UVIS4WvRrYbIblypAjK81XFnlq8zxUCiBFgFE=
|
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e h1:zTmKa/UVIS4WvRrYbIblypAjK81XFnlq8zxUCiBFgFE=
|
||||||
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e/go.mod h1:jF849JXyKVKRC0O62ZBSygt6qOSEYju8i90sKd1mx4g=
|
k8s.io/apimachinery v0.0.0-20230503174314-7ecc58659e5e/go.mod h1:jF849JXyKVKRC0O62ZBSygt6qOSEYju8i90sKd1mx4g=
|
||||||
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
|
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -340,8 +339,8 @@ func TestCreateBackoffManager(t *testing.T) {
|
|||||||
theUrl, _ := url.Parse("http://localhost")
|
theUrl, _ := url.Parse("http://localhost")
|
||||||
|
|
||||||
// 1 second base backoff + duration of 2 seconds -> exponential backoff for requests.
|
// 1 second base backoff + duration of 2 seconds -> exponential backoff for requests.
|
||||||
os.Setenv(envBackoffBase, "1")
|
t.Setenv(envBackoffBase, "1")
|
||||||
os.Setenv(envBackoffDuration, "2")
|
t.Setenv(envBackoffDuration, "2")
|
||||||
backoff := readExpBackoffConfig()
|
backoff := readExpBackoffConfig()
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
@ -350,8 +349,8 @@ func TestCreateBackoffManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0 duration -> no backoff.
|
// 0 duration -> no backoff.
|
||||||
os.Setenv(envBackoffBase, "1")
|
t.Setenv(envBackoffBase, "1")
|
||||||
os.Setenv(envBackoffDuration, "0")
|
t.Setenv(envBackoffDuration, "0")
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
backoff = readExpBackoffConfig()
|
backoff = readExpBackoffConfig()
|
||||||
@ -360,8 +359,8 @@ func TestCreateBackoffManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No env -> No backoff.
|
// No env -> No backoff.
|
||||||
os.Setenv(envBackoffBase, "")
|
t.Setenv(envBackoffBase, "")
|
||||||
os.Setenv(envBackoffDuration, "")
|
t.Setenv(envBackoffDuration, "")
|
||||||
backoff = readExpBackoffConfig()
|
backoff = readExpBackoffConfig()
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
backoff.UpdateBackoff(theUrl, nil, 500)
|
backoff.UpdateBackoff(theUrl, nil, 500)
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -80,23 +79,15 @@ func newLB(t *testing.T, serverURL string) *tcpLB {
|
|||||||
return &lb
|
return &lb
|
||||||
}
|
}
|
||||||
|
|
||||||
func setEnv(key, value string) func() {
|
|
||||||
originalValue := os.Getenv(key)
|
|
||||||
os.Setenv(key, value)
|
|
||||||
return func() {
|
|
||||||
os.Setenv(key, originalValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
readIdleTimeout int = 1
|
readIdleTimeout int = 1
|
||||||
pingTimeout int = 1
|
pingTimeout int = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReconnectBrokenTCP(t *testing.T) {
|
func TestReconnectBrokenTCP(t *testing.T) {
|
||||||
defer setEnv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", strconv.Itoa(readIdleTimeout))()
|
t.Setenv("HTTP2_READ_IDLE_TIMEOUT_SECONDS", strconv.Itoa(readIdleTimeout))
|
||||||
defer setEnv("HTTP2_PING_TIMEOUT_SECONDS", strconv.Itoa(pingTimeout))()
|
t.Setenv("HTTP2_PING_TIMEOUT_SECONDS", strconv.Itoa(pingTimeout))
|
||||||
defer setEnv("DISABLE_HTTP2", "")()
|
t.Setenv("DISABLE_HTTP2", "")
|
||||||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "Hello, %s", r.Proto)
|
fmt.Fprintf(w, "Hello, %s", r.Proto)
|
||||||
}))
|
}))
|
||||||
|
@ -897,12 +897,9 @@ func TestLoadingGetLoadingPrecedence(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeconfig := os.Getenv("KUBECONFIG")
|
|
||||||
defer os.Setenv("KUBECONFIG", kubeconfig)
|
|
||||||
|
|
||||||
for name, test := range testCases {
|
for name, test := range testCases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
os.Setenv("KUBECONFIG", test.env)
|
t.Setenv("KUBECONFIG", test.env)
|
||||||
rules := test.rules
|
rules := test.rules
|
||||||
if rules == nil {
|
if rules == nil {
|
||||||
rules = NewDefaultClientConfigLoadingRules()
|
rules = NewDefaultClientConfigLoadingRules()
|
||||||
|
Loading…
Reference in New Issue
Block a user