Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
fix(kubernetes): add tests for validate service and ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
linki committed Feb 13, 2017
1 parent 456f340 commit 7dc09b2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
42 changes: 42 additions & 0 deletions producers/ingress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package producers

import (
"testing"

"k8s.io/client-go/pkg/api/v1"
extensions "k8s.io/client-go/pkg/apis/extensions/v1beta1"
)

func TestValidateIngress(t *testing.T) {
loadBalancer := v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{v1.LoadBalancerIngress{IP: "8.8.8.8"}},
}

emptyIngress := extensions.Ingress{}

validIngress := extensions.Ingress{
Status: extensions.IngressStatus{LoadBalancer: loadBalancer},
}

validMatchedIngress := extensions.Ingress{
ObjectMeta: v1.ObjectMeta{Annotations: map[string]string{"foo": "bar"}},
Status: extensions.IngressStatus{LoadBalancer: loadBalancer},
}

for _, test := range []struct {
ingress extensions.Ingress
filter map[string]string
isErr bool
}{
{emptyIngress, map[string]string{}, false},
{validIngress, map[string]string{}, true},
{validIngress, map[string]string{"foo": "bar"}, false},
{validMatchedIngress, map[string]string{"foo": "bar"}, true},
{validMatchedIngress, map[string]string{"foo": "qux"}, false},
} {
result := validateIngress(test.ingress, test.filter)
if _, isErr := result.(error); isErr == test.isErr {
t.Errorf("validateIngress(%q, %q) => %q, want %t", test.ingress.Name, test.filter, result, test.isErr)
}
}
}
41 changes: 41 additions & 0 deletions producers/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package producers

import (
"testing"

"k8s.io/client-go/pkg/api/v1"
)

func TestValidateService(t *testing.T) {
loadBalancer := v1.LoadBalancerStatus{
Ingress: []v1.LoadBalancerIngress{v1.LoadBalancerIngress{IP: "8.8.8.8"}},
}

emptyService := v1.Service{}

validService := v1.Service{
Status: v1.ServiceStatus{LoadBalancer: loadBalancer},
}

validMatchedService := v1.Service{
ObjectMeta: v1.ObjectMeta{Annotations: map[string]string{"foo": "bar"}},
Status: v1.ServiceStatus{LoadBalancer: loadBalancer},
}

for _, test := range []struct {
service v1.Service
filter map[string]string
isErr bool
}{
{emptyService, map[string]string{}, false},
{validService, map[string]string{}, true},
{validService, map[string]string{"foo": "bar"}, false},
{validMatchedService, map[string]string{"foo": "bar"}, true},
{validMatchedService, map[string]string{"foo": "qux"}, false},
} {
result := validateService(test.service, test.filter)
if _, isErr := result.(error); isErr == test.isErr {
t.Errorf("validateService(%q, %q) => %q, want %t", test.service.Name, test.filter, result, test.isErr)
}
}
}

0 comments on commit 7dc09b2

Please sign in to comment.