Merge pull request #48104 from liggitt/tls-copy-bug

Automatic merge from submit-queue

Fix tls config copy in dial test

Fixes a bug introduced in 0d42da1b93 (diff-1748ffb7995a87b1f6bfd534dc5a51abL99) that broke the mutation test check (it was checking an object against itself)
pull/6/head
Kubernetes Submit Queue 2017-07-24 16:11:43 -07:00 committed by GitHub
commit d368afd845
2 changed files with 7 additions and 2 deletions

View File

@ -21,6 +21,7 @@ go_test(
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/golang.org/x/net/websocket:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
],

View File

@ -28,6 +28,7 @@ import (
"strings"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
utilnet "k8s.io/apimachinery/pkg/util/net"
)
@ -96,7 +97,10 @@ func TestDialURL(t *testing.T) {
ts.TLS = &tls.Config{Certificates: []tls.Certificate{cert}}
ts.StartTLS()
tlsConfigCopy := tc.TLSConfig
// Make a copy of the config
tlsConfigCopy := tc.TLSConfig.Clone()
// Clone() mutates the receiver (!), so also call it on the copy
tlsConfigCopy.Clone()
transport := &http.Transport{
Dial: tc.Dial,
TLSClientConfig: tlsConfigCopy,
@ -125,7 +129,7 @@ func TestDialURL(t *testing.T) {
// Make sure dialing doesn't mutate the transport's TLSConfig
if !reflect.DeepEqual(tc.TLSConfig, tlsConfigCopy) {
t.Errorf("%s: transport's copy of TLSConfig was mutated\n%#v\n\n%#v", k, tc.TLSConfig, tlsConfigCopy)
t.Errorf("%s: transport's copy of TLSConfig was mutated\n%s", k, diff.ObjectReflectDiff(tc.TLSConfig, tlsConfigCopy))
}
if err != nil {