refactor services to v1beta3

This commit is contained in:
markturansky
2014-10-30 09:29:11 -04:00
parent 5a649f2b93
commit bd7643c033
26 changed files with 466 additions and 340 deletions

View File

@@ -633,8 +633,10 @@ func TestValidateService(t *testing.T) {
name: "missing id",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
},
// Should fail because the ID is missing.
numErrs: 1,
@@ -643,8 +645,10 @@ func TestValidateService(t *testing.T) {
name: "missing namespace",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo"},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
},
// Should fail because the Namespace is missing.
numErrs: 1,
@@ -653,8 +657,10 @@ func TestValidateService(t *testing.T) {
name: "invalid id",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "123abc", Namespace: api.NamespaceDefault},
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
},
// Should fail because the ID is invalid.
numErrs: 1,
@@ -663,7 +669,9 @@ func TestValidateService(t *testing.T) {
name: "missing port",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Selector: map[string]string{"foo": "bar"},
},
},
// Should fail because the port number is missing/invalid.
numErrs: 1,
@@ -672,8 +680,10 @@ func TestValidateService(t *testing.T) {
name: "invalid port",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Port: 65536,
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 66536,
Selector: map[string]string{"foo": "bar"},
},
},
// Should fail because the port number is invalid.
numErrs: 1,
@@ -682,9 +692,11 @@ func TestValidateService(t *testing.T) {
name: "invalid protocol",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Port: 8675,
Protocol: "INVALID",
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Protocol: "INVALID",
},
},
// Should fail because the protocol is invalid.
numErrs: 1,
@@ -693,7 +705,9 @@ func TestValidateService(t *testing.T) {
name: "missing selector",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
Port: 8675,
Spec: api.ServiceSpec{
Port: 8675,
},
},
// Should fail because the selector is missing.
numErrs: 1,
@@ -702,9 +716,11 @@ func TestValidateService(t *testing.T) {
name: "valid 1",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Port: 1,
Protocol: "TCP",
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Protocol: "TCP",
},
},
numErrs: 0,
},
@@ -712,9 +728,11 @@ func TestValidateService(t *testing.T) {
name: "valid 2",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Port: 65535,
Protocol: "UDP",
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
Protocol: "UDP",
},
},
numErrs: 0,
},
@@ -722,8 +740,10 @@ func TestValidateService(t *testing.T) {
name: "valid 3",
svc: api.Service{
ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
Port: 80,
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
},
numErrs: 0,
},
@@ -737,8 +757,10 @@ func TestValidateService(t *testing.T) {
"NoUppercaseOrSpecialCharsLike=Equals": "bar",
},
},
Port: 80,
Selector: map[string]string{"foo": "bar", "NoUppercaseOrSpecialCharsLike=Equals": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar", "NoUppercaseOrSpecialCharsLike=Equals": "bar"},
},
},
numErrs: 2,
},
@@ -752,15 +774,17 @@ func TestValidateService(t *testing.T) {
}
svc := api.Service{
Port: 6502,
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
Selector: map[string]string{"foo": "bar"},
Spec: api.ServiceSpec{
Port: 8675,
Selector: map[string]string{"foo": "bar"},
},
}
errs := ValidateService(&svc)
if len(errs) != 0 {
t.Errorf("Unexpected non-zero error list: %#v", errs)
}
if svc.Protocol != "TCP" {
if svc.Spec.Protocol != "TCP" {
t.Errorf("Expected default protocol of 'TCP': %#v", errs)
}
}