Merge pull request #3566 from diazjf/unit-locs
Add Unit Tests for getIngressInformation
This commit is contained in:
commit
1b06cf7ed2
2 changed files with 92 additions and 0 deletions
|
@ -26,6 +26,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
text_template "text/template"
|
||||
|
@ -762,6 +763,23 @@ type ingressInformation struct {
|
|||
Annotations map[string]string
|
||||
}
|
||||
|
||||
func (info *ingressInformation) Equal(other *ingressInformation) bool {
|
||||
if info.Namespace != other.Namespace {
|
||||
return false
|
||||
}
|
||||
if info.Rule != other.Rule {
|
||||
return false
|
||||
}
|
||||
if info.Service != other.Service {
|
||||
return false
|
||||
}
|
||||
if !reflect.DeepEqual(info.Annotations, other.Annotations) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func getIngressInformation(i, p interface{}) *ingressInformation {
|
||||
ing, ok := i.(*ingress.Ingress)
|
||||
if !ok {
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
extensions "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
|
@ -843,3 +844,76 @@ func TestOpentracingPropagateContext(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIngressInformation(t *testing.T) {
|
||||
validIngress := &ingress.Ingress{}
|
||||
invalidIngress := "wrongtype"
|
||||
validPath := "/ok"
|
||||
invalidPath := 10
|
||||
|
||||
info := getIngressInformation(invalidIngress, validPath)
|
||||
expected := &ingressInformation{}
|
||||
if !info.Equal(expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, info)
|
||||
}
|
||||
|
||||
info = getIngressInformation(validIngress, invalidPath)
|
||||
if !info.Equal(expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, info)
|
||||
}
|
||||
|
||||
// Setup Ingress Resource
|
||||
validIngress.Namespace = "default"
|
||||
validIngress.Name = "validIng"
|
||||
validIngress.Annotations = map[string]string{
|
||||
"ingress.annotation": "ok",
|
||||
}
|
||||
validIngress.Spec.Backend = &extensions.IngressBackend{
|
||||
ServiceName: "a-svc",
|
||||
}
|
||||
|
||||
info = getIngressInformation(validIngress, validPath)
|
||||
expected = &ingressInformation{
|
||||
Namespace: "default",
|
||||
Rule: "validIng",
|
||||
Annotations: map[string]string{
|
||||
"ingress.annotation": "ok",
|
||||
},
|
||||
Service: "a-svc",
|
||||
}
|
||||
if !info.Equal(expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, info)
|
||||
}
|
||||
|
||||
validIngress.Spec.Backend = nil
|
||||
validIngress.Spec.Rules = []extensions.IngressRule{
|
||||
{
|
||||
IngressRuleValue: extensions.IngressRuleValue{
|
||||
HTTP: &extensions.HTTPIngressRuleValue{
|
||||
Paths: []extensions.HTTPIngressPath{
|
||||
{
|
||||
Path: "/ok",
|
||||
Backend: extensions.IngressBackend{
|
||||
ServiceName: "b-svc",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{},
|
||||
}
|
||||
|
||||
info = getIngressInformation(validIngress, validPath)
|
||||
expected = &ingressInformation{
|
||||
Namespace: "default",
|
||||
Rule: "validIng",
|
||||
Annotations: map[string]string{
|
||||
"ingress.annotation": "ok",
|
||||
},
|
||||
Service: "b-svc",
|
||||
}
|
||||
if !info.Equal(expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, info)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue