fix qemu and update docker with tests

This commit is contained in:
Mahmood Ali
2019-09-04 09:33:35 -04:00
parent 6190443d79
commit bd6bbc9ca8
5 changed files with 73 additions and 3 deletions

View File

@@ -786,9 +786,14 @@ func buildUpstreamsEnv(envMap map[string]string, upstreams []structs.ConsulUpstr
}
}
func WithPortMapEnvs(envs map[string]string, ports map[string]int) map[string]string {
// SetPortMapEnvs sets the PortMap related environment variables on the map
func SetPortMapEnvs(envs map[string]string, ports map[string]int) map[string]string {
if envs == nil {
envs = map[string]string{}
}
for portLabel, port := range ports {
portEnv := PortPrefix + portLabel
portEnv := helper.CleanEnvVar(PortPrefix+portLabel, '_')
envs[portEnv] = strconv.Itoa(port)
}
return envs

View File

@@ -784,3 +784,23 @@ func TestEnvironment_Upstreams(t *testing.T) {
require.Equal(t, "127.0.0.1:1234", env["foo"])
require.Equal(t, "1234", env["bar"])
}
func TestEnvironment_SetPortMapEnvs(t *testing.T) {
envs := map[string]string{
"foo": "bar",
"NOMAD_PORT_ssh": "2342",
}
ports := map[string]int{
"ssh": 22,
"http": 80,
}
envs = SetPortMapEnvs(envs, ports)
expected := map[string]string{
"foo": "bar",
"NOMAD_PORT_ssh": "22",
"NOMAD_PORT_http": "80",
}
require.Equal(t, expected, envs)
}