switch some commands to use its own scheme

This commit is contained in:
ymqytw
2017-10-27 18:31:42 -07:00
parent 35468469eb
commit 4487cc5e15
64 changed files with 362 additions and 450 deletions

View File

@@ -20,32 +20,32 @@ import (
"reflect"
"testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api"
)
func TestServiceBasicGenerate(t *testing.T) {
tests := []struct {
name string
serviceType api.ServiceType
serviceType v1.ServiceType
tcp []string
clusterip string
expected *api.Service
expected *v1.Service
expectErr bool
}{
{
name: "clusterip-ok",
tcp: []string{"456", "321:908"},
clusterip: "",
serviceType: api.ServiceTypeClusterIP,
expected: &api.Service{
serviceType: v1.ServiceTypeClusterIP,
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "clusterip-ok",
Labels: map[string]string{"app": "clusterip-ok"},
},
Spec: api.ServiceSpec{Type: "ClusterIP",
Ports: []api.ServicePort{{Name: "456", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 456, StrVal: ""}, NodePort: 0},
Spec: v1.ServiceSpec{Type: "ClusterIP",
Ports: []v1.ServicePort{{Name: "456", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 456, StrVal: ""}, NodePort: 0},
{Name: "321-908", Protocol: "TCP", Port: 321, TargetPort: intstr.IntOrString{Type: 0, IntVal: 908, StrVal: ""}, NodePort: 0}},
Selector: map[string]string{"app": "clusterip-ok"},
ClusterIP: "", ExternalIPs: []string(nil), LoadBalancerIP: ""},
@@ -54,28 +54,28 @@ func TestServiceBasicGenerate(t *testing.T) {
},
{
name: "clusterip-missing",
serviceType: api.ServiceTypeClusterIP,
serviceType: v1.ServiceTypeClusterIP,
expectErr: true,
},
{
name: "clusterip-none-wrong-type",
tcp: []string{},
clusterip: "None",
serviceType: api.ServiceTypeNodePort,
serviceType: v1.ServiceTypeNodePort,
expectErr: true,
},
{
name: "clusterip-none-ok",
tcp: []string{},
clusterip: "None",
serviceType: api.ServiceTypeClusterIP,
expected: &api.Service{
serviceType: v1.ServiceTypeClusterIP,
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "clusterip-none-ok",
Labels: map[string]string{"app": "clusterip-none-ok"},
},
Spec: api.ServiceSpec{Type: "ClusterIP",
Ports: []api.ServicePort{},
Spec: v1.ServiceSpec{Type: "ClusterIP",
Ports: []v1.ServicePort{},
Selector: map[string]string{"app": "clusterip-none-ok"},
ClusterIP: "None", ExternalIPs: []string(nil), LoadBalancerIP: ""},
},
@@ -85,14 +85,14 @@ func TestServiceBasicGenerate(t *testing.T) {
name: "clusterip-none-and-port-mapping",
tcp: []string{"456:9898"},
clusterip: "None",
serviceType: api.ServiceTypeClusterIP,
expected: &api.Service{
serviceType: v1.ServiceTypeClusterIP,
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "clusterip-none-and-port-mapping",
Labels: map[string]string{"app": "clusterip-none-and-port-mapping"},
},
Spec: api.ServiceSpec{Type: "ClusterIP",
Ports: []api.ServicePort{{Name: "456-9898", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 9898, StrVal: ""}, NodePort: 0}},
Spec: v1.ServiceSpec{Type: "ClusterIP",
Ports: []v1.ServicePort{{Name: "456-9898", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 9898, StrVal: ""}, NodePort: 0}},
Selector: map[string]string{"app": "clusterip-none-and-port-mapping"},
ClusterIP: "None", ExternalIPs: []string(nil), LoadBalancerIP: ""},
},
@@ -102,14 +102,14 @@ func TestServiceBasicGenerate(t *testing.T) {
name: "loadbalancer-ok",
tcp: []string{"456:9898"},
clusterip: "",
serviceType: api.ServiceTypeLoadBalancer,
expected: &api.Service{
serviceType: v1.ServiceTypeLoadBalancer,
expected: &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "loadbalancer-ok",
Labels: map[string]string{"app": "loadbalancer-ok"},
},
Spec: api.ServiceSpec{Type: "LoadBalancer",
Ports: []api.ServicePort{{Name: "456-9898", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 9898, StrVal: ""}, NodePort: 0}},
Spec: v1.ServiceSpec{Type: "LoadBalancer",
Ports: []v1.ServicePort{{Name: "456-9898", Protocol: "TCP", Port: 456, TargetPort: intstr.IntOrString{Type: 0, IntVal: 9898, StrVal: ""}, NodePort: 0}},
Selector: map[string]string{"app": "loadbalancer-ok"},
ClusterIP: "", ExternalIPs: []string(nil), LoadBalancerIP: ""},
},
@@ -133,8 +133,8 @@ func TestServiceBasicGenerate(t *testing.T) {
if test.expectErr && err != nil {
continue
}
if !reflect.DeepEqual(obj.(*api.Service), test.expected) {
t.Errorf("test: %v\nexpected:\n%#v\nsaw:\n%#v", test.name, test.expected, obj.(*api.Service))
if !reflect.DeepEqual(obj.(*v1.Service), test.expected) {
t.Errorf("test: %v\nexpected:\n%#v\nsaw:\n%#v", test.name, test.expected, obj.(*v1.Service))
}
}
}