2014-06-06 23:40:48 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-06-06 23:40:48 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2014-06-23 18:32:11 +00:00
|
|
|
|
2015-10-27 13:18:45 +00:00
|
|
|
package client
|
2014-06-06 23:40:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-01-19 18:27:59 +00:00
|
|
|
restclient "k8s.io/client-go/rest"
|
2016-12-14 01:18:17 +00:00
|
|
|
v1core "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1"
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
2016-10-07 19:30:45 +00:00
|
|
|
// Ensure a node client can be used as a NodeGetter.
|
|
|
|
// This allows anyone with a node client to easily construct a NewNodeConnectionInfoGetter.
|
2016-11-18 20:50:58 +00:00
|
|
|
var _ = NodeGetter(v1core.NodeInterface(nil))
|
2015-01-30 00:05:41 +00:00
|
|
|
|
2016-10-07 19:30:45 +00:00
|
|
|
func TestMakeTransportInvalid(t *testing.T) {
|
2015-10-27 13:18:45 +00:00
|
|
|
config := &KubeletClientConfig{
|
2014-12-16 06:57:27 +00:00
|
|
|
EnableHttps: true,
|
|
|
|
//Invalid certificate and key path
|
2016-02-12 18:58:43 +00:00
|
|
|
TLSClientConfig: restclient.TLSClientConfig{
|
2015-10-27 13:18:45 +00:00
|
|
|
CertFile: "../../client/testdata/mycertinvalid.cer",
|
|
|
|
KeyFile: "../../client/testdata/mycertinvalid.key",
|
|
|
|
CAFile: "../../client/testdata/myCA.cer",
|
2015-01-29 22:43:09 +00:00
|
|
|
},
|
2014-12-16 06:57:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 19:30:45 +00:00
|
|
|
rt, err := MakeTransport(config)
|
2014-12-16 06:57:27 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Expected an error")
|
|
|
|
}
|
2016-10-07 19:30:45 +00:00
|
|
|
if rt != nil {
|
|
|
|
t.Error("rt should be nil as we provided invalid cert file")
|
2014-12-16 06:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 19:30:45 +00:00
|
|
|
func TestMakeTransportValid(t *testing.T) {
|
2015-10-27 13:18:45 +00:00
|
|
|
config := &KubeletClientConfig{
|
2015-11-30 19:35:34 +00:00
|
|
|
Port: 1234,
|
2014-12-16 06:57:27 +00:00
|
|
|
EnableHttps: true,
|
2016-02-12 18:58:43 +00:00
|
|
|
TLSClientConfig: restclient.TLSClientConfig{
|
2015-10-27 13:18:45 +00:00
|
|
|
CertFile: "../../client/testdata/mycertvalid.cer",
|
2015-01-29 22:43:09 +00:00
|
|
|
// TLS Configuration, only applies if EnableHttps is true.
|
2015-10-27 13:18:45 +00:00
|
|
|
KeyFile: "../../client/testdata/mycertvalid.key",
|
2015-01-29 22:43:09 +00:00
|
|
|
// TLS Configuration, only applies if EnableHttps is true.
|
2015-10-27 13:18:45 +00:00
|
|
|
CAFile: "../../client/testdata/myCA.cer",
|
2015-01-29 22:43:09 +00:00
|
|
|
},
|
2014-12-16 06:57:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 19:30:45 +00:00
|
|
|
rt, err := MakeTransport(config)
|
2014-12-16 06:57:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Not expecting an error #%v", err)
|
|
|
|
}
|
2016-10-07 19:30:45 +00:00
|
|
|
if rt == nil {
|
|
|
|
t.Error("rt should not be nil")
|
2015-11-30 19:35:34 +00:00
|
|
|
}
|
2014-12-16 06:57:27 +00:00
|
|
|
}
|