Use ordered RemoveDuplicates. Add additional test cases.

This commit is contained in:
James Munnelly 2017-11-04 00:44:08 +00:00
parent a5b954658c
commit ffbfe2da3d
2 changed files with 21 additions and 9 deletions

View File

@ -57,15 +57,15 @@ func StringFilter(fn FilterFn, in ...string) StringFilterWrapper {
}
func RemoveDuplicates(in []string) []string {
dedupMap := make(map[string]struct{})
var found []string
Outer:
for _, i := range in {
dedupMap[i] = struct{}{}
for _, i2 := range found {
if i2 == i {
continue Outer
}
}
found = append(found, i)
}
out := make([]string, len(dedupMap))
i := 0
for s := range dedupMap {
out[i] = s
i++
}
return out
return found
}

View File

@ -102,6 +102,18 @@ func TestDNSNamesForCertificate(t *testing.T) {
crtDNSNames: []string{"dnsname1", "dnsname2"},
expectDNSNames: []string{"dnsname1", "dnsname2"},
},
{
name: "certificate with dnsName[0] set to equal common name",
crtCN: "cn",
crtDNSNames: []string{"cn", "dnsname"},
expectDNSNames: []string{"cn", "dnsname"},
},
{
name: "certificate with a dnsName equal to cn",
crtCN: "cn",
crtDNSNames: []string{"dnsname", "cn"},
expectDNSNames: []string{"cn", "dnsname"},
},
}
testFn := func(test testT) func(*testing.T) {
return func(t *testing.T) {