Move secretTracker updating to GetAuthCertificate()

This commit is contained in:
Joao Morais 2017-05-23 14:20:31 -03:00
parent 2ddf6c91df
commit c4d8011fa4
3 changed files with 4 additions and 105 deletions

View file

@ -264,79 +264,3 @@ func TestAffinitySession(t *testing.T) {
}
}
}
func TestContainsCertificateAuth(t *testing.T) {
ec := newAnnotationExtractor(mockCfg{})
foos := []struct {
name string
annotations map[string]string
result bool
}{
{"nil_annotations", nil, false},
{"empty_annotations", map[string]string{}, false},
{"not_exist_annotations", map[string]string{annotationAffinityType: "cookie"}, false},
{"exist_annotations", map[string]string{annotationAuthTlsSecret: "default/foo_secret"}, true},
}
for _, foo := range foos {
t.Run(foo.name, func(t *testing.T) {
ing := buildIngress()
ing.SetAnnotations(foo.annotations)
r := ec.ContainsCertificateAuth(ing)
if r != foo.result {
t.Errorf("Returned %t but expected %t for %s", r, foo.result, foo.name)
}
})
}
}
func TestCertificateAuthSecret(t *testing.T) {
resolver := mockCfg{}
resolver.MockSecrets = map[string]*api.Secret{
"default/foo_secret": {
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo_secret_name",
},
},
}
ec := newAnnotationExtractor(resolver)
foos := []struct {
name string
annotations map[string]string
eerr bool
ename string
}{
{"nil_annotations", nil, true, ""},
{"empty_annotations", map[string]string{}, true, ""},
{"not_exist_annotations", map[string]string{annotationAffinityType: "cookie"}, true, ""},
{"exist_annotations", map[string]string{annotationAuthTlsSecret: "default/foo_secret"}, false, "foo_secret_name"},
}
for _, foo := range foos {
t.Run(foo.name, func(t *testing.T) {
ing := buildIngress()
ing.SetAnnotations(foo.annotations)
r, err := ec.CertificateAuthSecret(ing)
if foo.eerr {
if err == nil {
t.Fatalf("Exepected error for %s", foo.name)
}
} else {
if err != nil {
t.Fatalf("Unexpected error %v for %s", err, foo.name)
}
rname := ""
if r != nil {
rname = r.GetName()
}
if rname != foo.ename {
t.Errorf("Returned %s but expected %s for %s", rname, foo.ename, foo.name)
}
}
})
}
}