Merge pull request #2399 from aledbf/add-tests
Add test for store helper ListIngresses
This commit is contained in:
commit
18a6a3051d
2 changed files with 106 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue