mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fn: cleanup of docker private registry code Start using URL parsed ServerAddress and its subdomains for easier image ensure/pull in docker driver. Previous code to lookup substrings was faulty without proper URL parse and hostname tokenization. When searching for a registry config, if image name does not contain a registry and if there's a private registry configured, then search for hub.docker.com and index.docker.io. This is similar to previous code but with correct subdomain matching. * fn-dataplane: take port into account in auth configs
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package docker
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func verify(expected []string, checks map[string]bool) bool {
|
|
if len(expected) != len(checks) {
|
|
return false
|
|
}
|
|
for _, v := range expected {
|
|
_, ok := checks[v]
|
|
if !ok {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func TestRegistrySubDomains(t *testing.T) {
|
|
var exp []string
|
|
var res map[string]bool
|
|
|
|
exp = []string{"google.com"}
|
|
res = getSubdomains("google.com")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
|
|
exp = []string{"top.google.com", "google.com"}
|
|
res = getSubdomains("top.google.com")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
|
|
exp = []string{"top.google.com:443", "google.com:443"}
|
|
res = getSubdomains("top.google.com:443")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
|
|
exp = []string{"top.top.google.com", "top.google.com", "google.com"}
|
|
res = getSubdomains("top.top.google.com")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
|
|
exp = []string{"docker"}
|
|
res = getSubdomains("docker")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
|
|
exp = []string{""}
|
|
res = getSubdomains("")
|
|
if !verify(exp, res) {
|
|
t.Fatalf("subdomain results failed expected[%+v] != results[%+v]", exp, res)
|
|
}
|
|
}
|