diff --git a/engine/env.go b/engine/env.go index 3e292107a7..9b8f639724 100644 --- a/engine/env.go +++ b/engine/env.go @@ -11,8 +11,10 @@ import ( type Env []string +// Get returns the last value associated with the given key. If there are no +// values associated with the key, Get returns the empty string. func (env *Env) Get(key string) (value string) { - // FIXME: use Map() + // not using Map() because of the extra allocations https://github.com/docker/docker/pull/7488#issuecomment-51638315 for _, kv := range *env { if strings.Index(kv, "=") == -1 { continue diff --git a/engine/env_test.go b/engine/env_test.go index fe1db04e33..b0caca9cbd 100644 --- a/engine/env_test.go +++ b/engine/env_test.go @@ -36,6 +36,18 @@ func TestEnvLenDup(t *testing.T) { } } +func TestEnvGetDup(t *testing.T) { + env := &Env{ + "foo=bar", + "foo=baz", + "foo=bif", + } + expected := "bif" + if v := env.Get("foo"); v != expected { + t.Fatalf("expect %q, got %q", expected, v) + } +} + func TestNewJob(t *testing.T) { job := mkJob(t, "dummy", "--level=awesome") if job.Name != "dummy" {