move IsLocalIP() and ShouldSkipService() to pkg/proxy/util
This commit is contained in:
111
pkg/proxy/util/utils_test.go
Normal file
111
pkg/proxy/util/utils_test.go
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
func TestShouldSkipService(t *testing.T) {
|
||||
testCases := []struct {
|
||||
service *api.Service
|
||||
svcName types.NamespacedName
|
||||
shouldSkip bool
|
||||
}{
|
||||
{
|
||||
// Cluster IP is None
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: api.ClusterIPNone,
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: true,
|
||||
},
|
||||
{
|
||||
// Cluster IP is empty
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: "",
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: true,
|
||||
},
|
||||
{
|
||||
// ExternalName type service
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: "1.2.3.4",
|
||||
Type: api.ServiceTypeExternalName,
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: true,
|
||||
},
|
||||
{
|
||||
// ClusterIP type service with ClusterIP set
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: "1.2.3.4",
|
||||
Type: api.ServiceTypeClusterIP,
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: false,
|
||||
},
|
||||
{
|
||||
// NodePort type service with ClusterIP set
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: "1.2.3.4",
|
||||
Type: api.ServiceTypeNodePort,
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: false,
|
||||
},
|
||||
{
|
||||
// LoadBalancer type service with ClusterIP set
|
||||
service: &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"},
|
||||
Spec: api.ServiceSpec{
|
||||
ClusterIP: "1.2.3.4",
|
||||
Type: api.ServiceTypeLoadBalancer,
|
||||
},
|
||||
},
|
||||
svcName: types.NamespacedName{Namespace: "foo", Name: "bar"},
|
||||
shouldSkip: false,
|
||||
},
|
||||
}
|
||||
|
||||
for i := range testCases {
|
||||
skip := ShouldSkipService(testCases[i].svcName, testCases[i].service)
|
||||
if skip != testCases[i].shouldSkip {
|
||||
t.Errorf("case %d: expect %v, got %v", i, testCases[i].shouldSkip, skip)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user