Skip to content

Commit

Permalink
Merge pull request #2399 from aledbf/add-tests
Browse files Browse the repository at this point in the history
Add test for store helper ListIngresses
  • Loading branch information
k8s-ci-robot committed Apr 22, 2018
2 parents 27fcee4 + c593236 commit 18a6a30
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/ingress/controller/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,19 @@ func (s k8sStore) ListIngresses() []*extensions.Ingress {
if !class.IsValid(ing) {
continue
}

for ri, rule := range ing.Spec.Rules {
if rule.HTTP == nil {
continue
}

for pi, path := range rule.HTTP.Paths {
if path.Path == "" {
ing.Spec.Rules[ri].HTTP.Paths[pi].Path = "/"
}
}
}

ingresses = append(ingresses, ing)
}

Expand Down
103 changes: 103 additions & 0 deletions internal/ingress/controller/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,106 @@ func TestUpdateSecretIngressMap(t *testing.T) {
}
})
}

func TestListIngresses(t *testing.T) {
s := newStore(t)

ingEmptyClass := &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test-1",
Namespace: "testns",
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "demo",
ServicePort: intstr.FromInt(80),
},
Rules: []v1beta1.IngressRule{
{
Host: "foo.bar",
},
},
},
}
s.listers.Ingress.Add(ingEmptyClass)

ingressToIgnore := &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test-2",
Namespace: "testns",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "something",
},
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "demo",
ServicePort: intstr.FromInt(80),
},
},
}
s.listers.Ingress.Add(ingressToIgnore)

ingressWithoutPath := &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test-3",
Namespace: "testns",
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{
Host: "foo.bar",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
{
Backend: v1beta1.IngressBackend{
ServiceName: "demo",
ServicePort: intstr.FromInt(80),
},
},
},
},
},
},
},
},
}
s.listers.Ingress.Add(ingressWithoutPath)

ingressWithNginxClass := &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test-4",
Namespace: "testns",
Annotations: map[string]string{
"kubernetes.io/ingress.class": "nginx",
},
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{
Host: "foo.bar",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
{
Path: "/demo",
Backend: v1beta1.IngressBackend{
ServiceName: "demo",
ServicePort: intstr.FromInt(80),
},
},
},
},
},
},
},
},
}
s.listers.Ingress.Add(ingressWithNginxClass)

ingresses := s.ListIngresses()
if s := len(ingresses); s != 3 {
t.Errorf("Expected 3 Ingresses but got %v", s)
}
}

0 comments on commit 18a6a30

Please sign in to comment.