Skip to content

Commit

Permalink
Don't take a reference a var in a loop
Browse files Browse the repository at this point in the history
Fixes #2491
  • Loading branch information
schmichael committed Mar 28, 2017
1 parent 8d5f2bb commit 24d27fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/driver/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
continue
}
for _, nw := range resources.Networks {
ports := make([]*structs.Port, 0, len(nw.ReservedPorts)+len(nw.DynamicPorts))
ports := make([]structs.Port, 0, len(nw.ReservedPorts)+len(nw.DynamicPorts))
for _, port := range nw.ReservedPorts {
ports = append(ports, &port)
ports = append(ports, port)
}
for _, port := range nw.DynamicPorts {
ports = append(ports, &port)
ports = append(ports, port)
}
for _, p := range ports {
key := fmt.Sprintf("%s%s_%s", AddrPrefix, taskName, p.Label)
Expand Down
16 changes: 16 additions & 0 deletions client/driver/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ func TestEnvironment_AsList(t *testing.T) {
n := mock.Node()
a := mock.Alloc()
a.TaskResources["web"].Networks[0].DynamicPorts[0].Value = 2000
a.TaskResources["ssh"] = &structs.Resources{
Networks: []*structs.NetworkResource{
{
ReservedPorts: []structs.Port{
{Label: "ssh", Value: 22},
{Label: "other", Value: 1234},
},
},
},
}
env := NewTaskEnvironment(n).
SetNetworks(networks).
SetPortMap(portMap).
Expand All @@ -165,6 +175,12 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_IP_web_main=192.168.0.100",
"NOMAD_IP_web_http=192.168.0.100",
"NOMAD_TASK_NAME=taskA",
"NOMAD_ADDR_ssh_other=:1234",
"NOMAD_ADDR_ssh_ssh=:22",
"NOMAD_IP_ssh_other=",
"NOMAD_IP_ssh_ssh=",
"NOMAD_PORT_ssh_other=1234",
"NOMAD_PORT_ssh_ssh=22",
}
allocID := fmt.Sprintf("NOMAD_ALLOC_ID=%s", a.ID)
exp = append(exp, allocID)
Expand Down

0 comments on commit 24d27fc

Please sign in to comment.