Skip to content

Commit

Permalink
test case added for hostHasTls
Browse files Browse the repository at this point in the history
Signed-off-by: பாலாஜி <rbalajis25@gmail.com>
  • Loading branch information
poonai committed Jan 13, 2018
1 parent 872da65 commit 59374a3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions internal/contour/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,56 @@ func TestValidTLSIngress(t *testing.T) {
}
}

func TestHostHasTls(t *testing.T) {
lc := new(ListenerCache)
s := make(map[metadata]*v1.Secret)
i := map[metadata]*v1beta1.Ingress{
metadata{name: "example", namespace: "default"}: &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "simple",
Namespace: "default",
},
Spec: v1beta1.IngressSpec{
TLS: []v1beta1.IngressTLS{{
Hosts: []string{"whatever.example.com"},
SecretName: "secret",
}},
Backend: backend("backend", intstr.FromInt(80)),
},
},
}
s[metadata{name: "secret", namespace: "default"}] = &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "secret",
Namespace: "default",
},
}
lc.recomputeTLSListener(i, s)
tests := map[string]struct {
sniName string
valid bool
}{
"valid sni": {
sniName: "whatever.example.com",
valid: true,
},
"invalid sni": {
sniName: "demo.example.com",
valid: false,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := lc.HostHasTls(tc.sniName)
want := tc.valid
if got != want {
t.Fatalf("hostHasTls: got: %v, want: %v", got, want)
}
})
}
}

func assertCacheEmpty(t *testing.T, lc *ListenerCache) {
t.Helper()
if len(lc.values) > 0 {
Expand Down

0 comments on commit 59374a3

Please sign in to comment.