Introduce a new service generator that leaves service port unnamed

This commit is contained in:
nikhiljindal
2015-07-16 14:18:17 -07:00
parent 59bc8db554
commit 496f30a92f
8 changed files with 92 additions and 29 deletions

View File

@@ -26,10 +26,12 @@ import (
func TestGenerateService(t *testing.T) {
tests := []struct {
params map[string]string
expected api.Service
generator Generator
params map[string]string
expected api.Service
}{
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -48,7 +50,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
@@ -58,6 +59,8 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -76,7 +79,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
@@ -86,6 +88,7 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"labels": "key1=value1,key2=value2",
@@ -109,7 +112,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
@@ -119,6 +121,7 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -138,7 +141,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
@@ -149,6 +151,7 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -169,7 +172,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
@@ -181,6 +183,7 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -200,7 +203,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
@@ -211,6 +213,7 @@ func TestGenerateService(t *testing.T) {
},
},
{
generator: ServiceGeneratorV2{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
@@ -231,7 +234,6 @@ func TestGenerateService(t *testing.T) {
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "UDP",
TargetPort: util.NewIntOrStringFromString("foobar"),
@@ -241,10 +243,38 @@ func TestGenerateService(t *testing.T) {
},
},
},
{
generator: ServiceGeneratorV1{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
"port": "80",
"protocol": "TCP",
"container-port": "1234",
},
expected: api.Service{
ObjectMeta: api.ObjectMeta{
Name: "test",
},
Spec: api.ServiceSpec{
Selector: map[string]string{
"foo": "bar",
"baz": "blah",
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
},
},
},
},
},
}
generator := ServiceGenerator{}
for _, test := range tests {
obj, err := generator.Generate(test.params)
obj, err := test.generator.Generate(test.params)
if !reflect.DeepEqual(obj, &test.expected) {
t.Errorf("expected:\n%#v\ngot\n%#v\n", &test.expected, obj)
}