Browse code

engine.Env: comments and tests for Get()

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Vincent Batts authored on 2014/09/11 11:20:20
Showing 2 changed files
... ...
@@ -11,8 +11,10 @@ import (
11 11
 
12 12
 type Env []string
13 13
 
14
+// Get returns the last value associated with the given key. If there are no
15
+// values associated with the key, Get returns the empty string.
14 16
 func (env *Env) Get(key string) (value string) {
15
-	// FIXME: use Map()
17
+	// not using Map() because of the extra allocations https://github.com/docker/docker/pull/7488#issuecomment-51638315
16 18
 	for _, kv := range *env {
17 19
 		if strings.Index(kv, "=") == -1 {
18 20
 			continue
... ...
@@ -36,6 +36,18 @@ func TestEnvLenDup(t *testing.T) {
36 36
 	}
37 37
 }
38 38
 
39
+func TestEnvGetDup(t *testing.T) {
40
+	env := &Env{
41
+		"foo=bar",
42
+		"foo=baz",
43
+		"foo=bif",
44
+	}
45
+	expected := "bif"
46
+	if v := env.Get("foo"); v != expected {
47
+		t.Fatalf("expect %q, got %q", expected, v)
48
+	}
49
+}
50
+
39 51
 func TestNewJob(t *testing.T) {
40 52
 	job := mkJob(t, "dummy", "--level=awesome")
41 53
 	if job.Name != "dummy" {