Make validation check for legal serive port numbers.

This commit is contained in:
Satnam Singh
2014-08-22 14:44:21 -07:00
parent bd2cbdc312
commit 7fcaf80f67
3 changed files with 30 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
fake_cloud "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/fake"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/minion"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest"
@@ -34,6 +34,7 @@ func TestServiceRegistryCreate(t *testing.T) {
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
}
@@ -60,6 +61,7 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
storage := NewRegistryStorage(registry, nil, nil)
failureCases := map[string]api.Service{
"empty ID": {
Port: 6502,
JSONBase: api.JSONBase{ID: ""},
Selector: map[string]string{"bar": "baz"},
},
@@ -82,11 +84,13 @@ func TestServiceStorageValidatesCreate(t *testing.T) {
func TestServiceRegistryUpdate(t *testing.T) {
registry := registrytest.NewServiceRegistry()
registry.CreateService(api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz1"},
})
storage := NewRegistryStorage(registry, nil, nil)
c, err := storage.Update(&api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz2"},
})
@@ -109,16 +113,19 @@ func TestServiceRegistryUpdate(t *testing.T) {
func TestServiceStorageValidatesUpdate(t *testing.T) {
registry := registrytest.NewServiceRegistry()
registry.CreateService(api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
})
storage := NewRegistryStorage(registry, nil, nil)
failureCases := map[string]api.Service{
"empty ID": {
Port: 6502,
JSONBase: api.JSONBase{ID: ""},
Selector: map[string]string{"bar": "baz"},
},
"empty selector": {
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{},
},
@@ -140,6 +147,7 @@ func TestServiceRegistryExternalService(t *testing.T) {
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
CreateExternalLoadBalancer: true,
@@ -166,6 +174,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) {
machines := []string{"foo", "bar", "baz"}
storage := NewRegistryStorage(registry, fakeCloud, minion.NewRegistry(machines))
svc := &api.Service{
Port: 6502,
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
CreateExternalLoadBalancer: true,