Browse code

Remove api_params.go

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/01/25 16:15:40
Showing 4 changed files
... ...
@@ -89,18 +89,10 @@ func httpError(w http.ResponseWriter, err error) {
89 89
 	}
90 90
 }
91 91
 
92
-func writeJSON(w http.ResponseWriter, code int, v interface{}) error {
93
-	b, err := json.Marshal(v)
94
-
95
-	if err != nil {
96
-		return err
97
-	}
98
-
92
+func writeJSON(w http.ResponseWriter, code int, v engine.Env) error {
99 93
 	w.Header().Set("Content-Type", "application/json")
100 94
 	w.WriteHeader(code)
101
-	w.Write(b)
102
-
103
-	return nil
95
+	return v.Encode(w)
104 96
 }
105 97
 
106 98
 func getBoolParam(value string) (bool, error) {
... ...
@@ -352,12 +344,15 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
352 352
 	if err := parseForm(r); err != nil {
353 353
 		return err
354 354
 	}
355
-	config := &Config{}
355
+	var (
356
+		config = &Config{}
357
+		env    engine.Env
358
+		job    = srv.Eng.Job("commit", r.Form.Get("container"))
359
+	)
356 360
 	if err := json.NewDecoder(r.Body).Decode(config); err != nil && err != io.EOF {
357 361
 		utils.Errorf("%s", err)
358 362
 	}
359 363
 
360
-	job := srv.Eng.Job("commit", r.Form.Get("container"))
361 364
 	job.Setenv("repo", r.Form.Get("repo"))
362 365
 	job.Setenv("tag", r.Form.Get("tag"))
363 366
 	job.Setenv("author", r.Form.Get("author"))
... ...
@@ -369,8 +364,8 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
369 369
 	if err := job.Run(); err != nil {
370 370
 		return err
371 371
 	}
372
-
373
-	return writeJSON(w, http.StatusCreated, &APIID{id})
372
+	env.Set("Id", id)
373
+	return writeJSON(w, http.StatusCreated, env)
374 374
 }
375 375
 
376 376
 // Creates an image from Pull or from Import
... ...
@@ -555,15 +550,19 @@ func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r
555 555
 	if err := parseForm(r); err != nil {
556 556
 		return nil
557 557
 	}
558
-	out := &APIRun{}
559
-	job := srv.Eng.Job("create", r.Form.Get("name"))
558
+	var (
559
+		out         engine.Env
560
+		job         = srv.Eng.Job("create", r.Form.Get("name"))
561
+		outWarnings []string
562
+		outId       string
563
+		warnings    = bytes.NewBuffer(nil)
564
+	)
560 565
 	if err := job.DecodeEnv(r.Body); err != nil {
561 566
 		return err
562 567
 	}
563 568
 	// Read container ID from the first line of stdout
564
-	job.Stdout.AddString(&out.ID)
569
+	job.Stdout.AddString(&outId)
565 570
 	// Read warnings from stderr
566
-	warnings := &bytes.Buffer{}
567 571
 	job.Stderr.Add(warnings)
568 572
 	if err := job.Run(); err != nil {
569 573
 		return err
... ...
@@ -571,8 +570,10 @@ func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r
571 571
 	// Parse warnings from stderr
572 572
 	scanner := bufio.NewScanner(warnings)
573 573
 	for scanner.Scan() {
574
-		out.Warnings = append(out.Warnings, scanner.Text())
574
+		outWarnings = append(outWarnings, scanner.Text())
575 575
 	}
576
+	out.Set("Id", outId)
577
+	out.SetList("Warnings", outWarnings)
576 578
 	return writeJSON(w, http.StatusCreated, out)
577 579
 }
578 580
 
... ...
@@ -664,18 +665,22 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
664 664
 	if vars == nil {
665 665
 		return fmt.Errorf("Missing parameter")
666 666
 	}
667
-	job := srv.Eng.Job("wait", vars["name"])
668
-	var statusStr string
669
-	job.Stdout.AddString(&statusStr)
667
+	var (
668
+		env    engine.Env
669
+		status string
670
+		job    = srv.Eng.Job("wait", vars["name"])
671
+	)
672
+	job.Stdout.AddString(&status)
670 673
 	if err := job.Run(); err != nil {
671 674
 		return err
672 675
 	}
673 676
 	// Parse a 16-bit encoded integer to map typical unix exit status.
674
-	status, err := strconv.ParseInt(statusStr, 10, 16)
677
+	_, err := strconv.ParseInt(status, 10, 16)
675 678
 	if err != nil {
676 679
 		return err
677 680
 	}
678
-	return writeJSON(w, http.StatusOK, &APIWait{StatusCode: int(status)})
681
+	env.Set("StatusCode", status)
682
+	return writeJSON(w, http.StatusOK, env)
679 683
 }
680 684
 
681 685
 func postContainersResize(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
... ...
@@ -874,24 +879,24 @@ func postContainersCopy(srv *Server, version float64, w http.ResponseWriter, r *
874 874
 		return fmt.Errorf("Missing parameter")
875 875
 	}
876 876
 
877
-	copyData := &APICopy{}
878
-	contentType := r.Header.Get("Content-Type")
879
-	if contentType == "application/json" {
880
-		if err := json.NewDecoder(r.Body).Decode(copyData); err != nil {
877
+	var copyData engine.Env
878
+
879
+	if contentType := r.Header.Get("Content-Type"); contentType == "application/json" {
880
+		if err := copyData.Decode(r.Body); err != nil {
881 881
 			return err
882 882
 		}
883 883
 	} else {
884 884
 		return fmt.Errorf("Content-Type not supported: %s", contentType)
885 885
 	}
886 886
 
887
-	if copyData.Resource == "" {
887
+	if copyData.Get("Resource") == "" {
888 888
 		return fmt.Errorf("Path cannot be empty")
889 889
 	}
890
-	if copyData.Resource[0] == '/' {
891
-		copyData.Resource = copyData.Resource[1:]
890
+	if copyData.Get("Resource")[0] == '/' {
891
+		copyData.Set("Resource", copyData.Get("Resource")[1:])
892 892
 	}
893 893
 
894
-	job := srv.Eng.Job("container_copy", vars["name"], copyData.Resource)
894
+	job := srv.Eng.Job("container_copy", vars["name"], copyData.Get("Resource"))
895 895
 	job.Stdout.Add(w)
896 896
 	if err := job.Run(); err != nil {
897 897
 		utils.Errorf("%s", err.Error())
898 898
deleted file mode 100644
... ...
@@ -1,43 +0,0 @@
1
-package docker
2
-
3
-type (
4
-	APITop struct {
5
-		Titles    []string
6
-		Processes [][]string
7
-	}
8
-
9
-	APIRmi struct {
10
-		Deleted  string `json:",omitempty"`
11
-		Untagged string `json:",omitempty"`
12
-	}
13
-
14
-	APIID struct {
15
-		ID string `json:"Id"`
16
-	}
17
-
18
-	APIRun struct {
19
-		ID       string   `json:"Id"`
20
-		Warnings []string `json:",omitempty"`
21
-	}
22
-
23
-	APIPort struct {
24
-		PrivatePort int64
25
-		PublicPort  int64
26
-		Type        string
27
-		IP          string
28
-	}
29
-
30
-	APIWait struct {
31
-		StatusCode int
32
-	}
33
-
34
-	APIImageConfig struct {
35
-		ID string `json:"Id"`
36
-		*Config
37
-	}
38
-
39
-	APICopy struct {
40
-		Resource string
41
-		HostPath string
42
-	}
43
-)
... ...
@@ -755,18 +755,21 @@ func (cli *DockerCli) CmdTop(args ...string) error {
755 755
 		val.Set("ps_args", strings.Join(cmd.Args()[1:], " "))
756 756
 	}
757 757
 
758
-	body, _, err := readBody(cli.call("GET", "/containers/"+cmd.Arg(0)+"/top?"+val.Encode(), nil, false))
758
+	stream, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/top?"+val.Encode(), nil, false)
759 759
 	if err != nil {
760 760
 		return err
761 761
 	}
762
-	procs := APITop{}
763
-	err = json.Unmarshal(body, &procs)
764
-	if err != nil {
762
+	var procs engine.Env
763
+	if err := procs.Decode(stream); err != nil {
765 764
 		return err
766 765
 	}
767 766
 	w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
768
-	fmt.Fprintln(w, strings.Join(procs.Titles, "\t"))
769
-	for _, proc := range procs.Processes {
767
+	fmt.Fprintln(w, strings.Join(procs.GetList("Titles"), "\t"))
768
+	processes := [][]string{}
769
+	if err := procs.GetJson("Processes", &processes); err != nil {
770
+		return err
771
+	}
772
+	for _, proc := range processes {
770 773
 		fmt.Fprintln(w, strings.Join(proc, "\t"))
771 774
 	}
772 775
 	w.Flush()
... ...
@@ -1451,25 +1454,25 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
1451 1451
 	v.Set("tag", tag)
1452 1452
 	v.Set("comment", *flComment)
1453 1453
 	v.Set("author", *flAuthor)
1454
-	var config *Config
1454
+	var (
1455
+		config *Config
1456
+		env    engine.Env
1457
+	)
1455 1458
 	if *flConfig != "" {
1456 1459
 		config = &Config{}
1457 1460
 		if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
1458 1461
 			return err
1459 1462
 		}
1460 1463
 	}
1461
-	body, _, err := readBody(cli.call("POST", "/commit?"+v.Encode(), config, false))
1464
+	stream, _, err := cli.call("POST", "/commit?"+v.Encode(), config, false)
1462 1465
 	if err != nil {
1463 1466
 		return err
1464 1467
 	}
1465
-
1466
-	apiID := &APIID{}
1467
-	err = json.Unmarshal(body, apiID)
1468
-	if err != nil {
1468
+	if err := env.Decode(stream); err != nil {
1469 1469
 		return err
1470 1470
 	}
1471 1471
 
1472
-	fmt.Fprintf(cli.out, "%s\n", apiID.ID)
1472
+	fmt.Fprintf(cli.out, "%s\n", env.Get("ID"))
1473 1473
 	return nil
1474 1474
 }
1475 1475
 
... ...
@@ -1989,7 +1992,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
1989 1989
 	}
1990 1990
 
1991 1991
 	//create the container
1992
-	body, statusCode, err := readBody(cli.call("POST", "/containers/create?"+containerValues.Encode(), config, false))
1992
+	stream, statusCode, err := cli.call("POST", "/containers/create?"+containerValues.Encode(), config, false)
1993 1993
 	//if image not found try to pull it
1994 1994
 	if statusCode == 404 {
1995 1995
 		_, tag := utils.ParseRepositoryTag(config.Image)
... ...
@@ -2026,30 +2029,30 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2026 2026
 		if err = cli.stream("POST", "/images/create?"+v.Encode(), nil, cli.err, map[string][]string{"X-Registry-Auth": registryAuthHeader}); err != nil {
2027 2027
 			return err
2028 2028
 		}
2029
-		if body, _, err = readBody(cli.call("POST", "/containers/create?"+containerValues.Encode(), config, false)); err != nil {
2029
+		if stream, _, err = cli.call("POST", "/containers/create?"+containerValues.Encode(), config, false); err != nil {
2030 2030
 			return err
2031 2031
 		}
2032 2032
 	} else if err != nil {
2033 2033
 		return err
2034 2034
 	}
2035 2035
 
2036
-	var runResult APIRun
2037
-	if err := json.Unmarshal(body, &runResult); err != nil {
2036
+	var runResult engine.Env
2037
+	if err := runResult.Decode(stream); err != nil {
2038 2038
 		return err
2039 2039
 	}
2040 2040
 
2041
-	for _, warning := range runResult.Warnings {
2041
+	for _, warning := range runResult.GetList("Warnings") {
2042 2042
 		fmt.Fprintf(cli.err, "WARNING: %s\n", warning)
2043 2043
 	}
2044 2044
 
2045 2045
 	if len(hostConfig.ContainerIDFile) > 0 {
2046
-		if _, err = containerIDFile.Write([]byte(runResult.ID)); err != nil {
2046
+		if _, err = containerIDFile.Write([]byte(runResult.Get("Id"))); err != nil {
2047 2047
 			return fmt.Errorf("failed to write the container ID to the file: %s", err)
2048 2048
 		}
2049 2049
 	}
2050 2050
 
2051 2051
 	if sigProxy {
2052
-		sigc := cli.forwardAllSignals(runResult.ID)
2052
+		sigc := cli.forwardAllSignals(runResult.Get("Id"))
2053 2053
 		defer utils.StopCatch(sigc)
2054 2054
 	}
2055 2055
 
... ...
@@ -2063,7 +2066,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2063 2063
 		waitDisplayId = make(chan struct{})
2064 2064
 		go func() {
2065 2065
 			defer close(waitDisplayId)
2066
-			fmt.Fprintf(cli.out, "%s\n", runResult.ID)
2066
+			fmt.Fprintf(cli.out, "%s\n", runResult.Get("Id"))
2067 2067
 		}()
2068 2068
 	}
2069 2069
 
... ...
@@ -2105,7 +2108,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2105 2105
 		}
2106 2106
 
2107 2107
 		errCh = utils.Go(func() error {
2108
-			return cli.hijack("POST", "/containers/"+runResult.ID+"/attach?"+v.Encode(), config.Tty, in, out, stderr, hijacked)
2108
+			return cli.hijack("POST", "/containers/"+runResult.Get("Id")+"/attach?"+v.Encode(), config.Tty, in, out, stderr, hijacked)
2109 2109
 		})
2110 2110
 	} else {
2111 2111
 		close(hijacked)
... ...
@@ -2127,12 +2130,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2127 2127
 	}
2128 2128
 
2129 2129
 	//start the container
2130
-	if _, _, err = readBody(cli.call("POST", "/containers/"+runResult.ID+"/start", hostConfig, false)); err != nil {
2130
+	if _, _, err = readBody(cli.call("POST", "/containers/"+runResult.Get("Id")+"/start", hostConfig, false)); err != nil {
2131 2131
 		return err
2132 2132
 	}
2133 2133
 
2134 2134
 	if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && cli.isTerminal {
2135
-		if err := cli.monitorTtySize(runResult.ID); err != nil {
2135
+		if err := cli.monitorTtySize(runResult.Get("Id")); err != nil {
2136 2136
 			utils.Errorf("Error monitoring TTY size: %s\n", err)
2137 2137
 		}
2138 2138
 	}
... ...
@@ -2157,26 +2160,26 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2157 2157
 	if autoRemove {
2158 2158
 		// Autoremove: wait for the container to finish, retrieve
2159 2159
 		// the exit code and remove the container
2160
-		if _, _, err := readBody(cli.call("POST", "/containers/"+runResult.ID+"/wait", nil, false)); err != nil {
2160
+		if _, _, err := readBody(cli.call("POST", "/containers/"+runResult.Get("Id")+"/wait", nil, false)); err != nil {
2161 2161
 			return err
2162 2162
 		}
2163
-		if _, status, err = getExitCode(cli, runResult.ID); err != nil {
2163
+		if _, status, err = getExitCode(cli, runResult.Get("Id")); err != nil {
2164 2164
 			return err
2165 2165
 		}
2166
-		if _, _, err := readBody(cli.call("DELETE", "/containers/"+runResult.ID+"?v=1", nil, false)); err != nil {
2166
+		if _, _, err := readBody(cli.call("DELETE", "/containers/"+runResult.Get("Id")+"?v=1", nil, false)); err != nil {
2167 2167
 			return err
2168 2168
 		}
2169 2169
 	} else {
2170 2170
 		if !config.Tty {
2171 2171
 			// In non-tty mode, we can't dettach, so we know we need to wait.
2172
-			if status, err = waitForExit(cli, runResult.ID); err != nil {
2172
+			if status, err = waitForExit(cli, runResult.Get("Id")); err != nil {
2173 2173
 				return err
2174 2174
 			}
2175 2175
 		} else {
2176 2176
 			// In TTY mode, there is a race. If the process dies too slowly, the state can be update after the getExitCode call
2177 2177
 			// and result in a wrong exit code.
2178 2178
 			// No Autoremove: Simply retrieve the exit code
2179
-			if _, status, err = getExitCode(cli, runResult.ID); err != nil {
2179
+			if _, status, err = getExitCode(cli, runResult.Get("Id")); err != nil {
2180 2180
 				return err
2181 2181
 			}
2182 2182
 		}
... ...
@@ -2198,15 +2201,15 @@ func (cli *DockerCli) CmdCp(args ...string) error {
2198 2198
 		return nil
2199 2199
 	}
2200 2200
 
2201
-	var copyData APICopy
2201
+	var copyData engine.Env
2202 2202
 	info := strings.Split(cmd.Arg(0), ":")
2203 2203
 
2204 2204
 	if len(info) != 2 {
2205 2205
 		return fmt.Errorf("Error: Path not specified")
2206 2206
 	}
2207 2207
 
2208
-	copyData.Resource = info[1]
2209
-	copyData.HostPath = cmd.Arg(1)
2208
+	copyData.Set("Resource", info[1])
2209
+	copyData.Set("HostPath", cmd.Arg(1))
2210 2210
 
2211 2211
 	stream, statusCode, err := cli.call("POST", "/containers/"+info[0]+"/copy", copyData, false)
2212 2212
 	if stream != nil {
... ...
@@ -2217,7 +2220,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
2217 2217
 	}
2218 2218
 
2219 2219
 	if statusCode == 200 {
2220
-		if err := archive.Untar(stream, copyData.HostPath, nil); err != nil {
2220
+		if err := archive.Untar(stream, copyData.Get("HostPath"), nil); err != nil {
2221 2221
 			return err
2222 2222
 		}
2223 2223
 	}
... ...
@@ -2260,13 +2263,21 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
2260 2260
 }
2261 2261
 
2262 2262
 func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) {
2263
-	var params io.Reader
2263
+	params := bytes.NewBuffer(nil)
2264 2264
 	if data != nil {
2265
-		buf, err := json.Marshal(data)
2266
-		if err != nil {
2267
-			return nil, -1, err
2265
+		if env, ok := data.(engine.Env); ok {
2266
+			if err := env.Encode(params); err != nil {
2267
+				return nil, -1, err
2268
+			}
2269
+		} else {
2270
+			buf, err := json.Marshal(data)
2271
+			if err != nil {
2272
+				return nil, -1, err
2273
+			}
2274
+			if _, err := params.Write(buf); err != nil {
2275
+				return nil, -1, err
2276
+			}
2268 2277
 		}
2269
-		params = bytes.NewBuffer(buf)
2270 2278
 	}
2271 2279
 	// fixme: refactor client to support redirect
2272 2280
 	re := regexp.MustCompile("/+")
... ...
@@ -2569,16 +2580,16 @@ func (cli *DockerCli) LoadConfigFile() (err error) {
2569 2569
 }
2570 2570
 
2571 2571
 func waitForExit(cli *DockerCli, containerId string) (int, error) {
2572
-	body, _, err := readBody(cli.call("POST", "/containers/"+containerId+"/wait", nil, false))
2572
+	stream, _, err := cli.call("POST", "/containers/"+containerId+"/wait", nil, false)
2573 2573
 	if err != nil {
2574 2574
 		return -1, err
2575 2575
 	}
2576 2576
 
2577
-	var out APIWait
2578
-	if err := json.Unmarshal(body, &out); err != nil {
2577
+	var out engine.Env
2578
+	if err := out.Decode(stream); err != nil {
2579 2579
 		return -1, err
2580 2580
 	}
2581
-	return out.StatusCode, nil
2581
+	return out.GetInt("StatusCode"), nil
2582 2582
 }
2583 2583
 
2584 2584
 // getExitCode perform an inspect on the container. It returns
... ...
@@ -485,26 +485,29 @@ func TestGetContainersTop(t *testing.T) {
485 485
 		t.Fatal(err)
486 486
 	}
487 487
 	assertHttpNotError(r, t)
488
-	procs := docker.APITop{}
489
-	if err := json.Unmarshal(r.Body.Bytes(), &procs); err != nil {
488
+	var procs engine.Env
489
+	if err := procs.Decode(r.Body); err != nil {
490 490
 		t.Fatal(err)
491 491
 	}
492 492
 
493
-	if len(procs.Titles) != 11 {
494
-		t.Fatalf("Expected 11 titles, found %d.", len(procs.Titles))
493
+	if len(procs.GetList("Titles")) != 11 {
494
+		t.Fatalf("Expected 11 titles, found %d.", len(procs.GetList("Titles")))
495 495
 	}
496
-	if procs.Titles[0] != "USER" || procs.Titles[10] != "COMMAND" {
497
-		t.Fatalf("Expected Titles[0] to be USER and Titles[10] to be COMMAND, found %s and %s.", procs.Titles[0], procs.Titles[10])
496
+	if procs.GetList("Titles")[0] != "USER" || procs.GetList("Titles")[10] != "COMMAND" {
497
+		t.Fatalf("Expected Titles[0] to be USER and Titles[10] to be COMMAND, found %s and %s.", procs.GetList("Titles")[0], procs.GetList("Titles")[10])
498 498
 	}
499
-
500
-	if len(procs.Processes) != 2 {
501
-		t.Fatalf("Expected 2 processes, found %d.", len(procs.Processes))
499
+	processes := [][]string{}
500
+	if err := procs.GetJson("Processes", &processes); err != nil {
501
+		t.Fatal(err)
502 502
 	}
503
-	if procs.Processes[0][10] != "/bin/sh -c cat" {
504
-		t.Fatalf("Expected `/bin/sh -c cat`, found %s.", procs.Processes[0][10])
503
+	if len(processes) != 2 {
504
+		t.Fatalf("Expected 2 processes, found %d.", len(processes))
505 505
 	}
506
-	if procs.Processes[1][10] != "/bin/sh -c cat" {
507
-		t.Fatalf("Expected `/bin/sh -c cat`, found %s.", procs.Processes[1][10])
506
+	if processes[0][10] != "/bin/sh -c cat" {
507
+		t.Fatalf("Expected `/bin/sh -c cat`, found %s.", processes[0][10])
508
+	}
509
+	if processes[1][10] != "/bin/sh -c cat" {
510
+		t.Fatalf("Expected `/bin/sh -c cat`, found %s.", processes[1][10])
508 511
 	}
509 512
 }
510 513
 
... ...
@@ -570,11 +573,11 @@ func TestPostCommit(t *testing.T) {
570 570
 		t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
571 571
 	}
572 572
 
573
-	apiID := &docker.APIID{}
574
-	if err := json.Unmarshal(r.Body.Bytes(), apiID); err != nil {
573
+	var env engine.Env
574
+	if err := env.Decode(r.Body); err != nil {
575 575
 		t.Fatal(err)
576 576
 	}
577
-	if _, err := srv.ImageInspect(apiID.ID); err != nil {
577
+	if _, err := srv.ImageInspect(env.Get("Id")); err != nil {
578 578
 		t.Fatalf("The image has not been committed")
579 579
 	}
580 580
 }
... ...
@@ -607,11 +610,11 @@ func TestPostContainersCreate(t *testing.T) {
607 607
 		t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
608 608
 	}
609 609
 
610
-	apiRun := &docker.APIRun{}
611
-	if err := json.Unmarshal(r.Body.Bytes(), apiRun); err != nil {
610
+	var apiRun engine.Env
611
+	if err := apiRun.Decode(r.Body); err != nil {
612 612
 		t.Fatal(err)
613 613
 	}
614
-	containerID := apiRun.ID
614
+	containerID := apiRun.Get("Id")
615 615
 
616 616
 	containerAssertExists(eng, containerID, t)
617 617
 	containerRun(eng, containerID, t)
... ...
@@ -863,12 +866,12 @@ func TestPostContainersWait(t *testing.T) {
863 863
 			t.Fatal(err)
864 864
 		}
865 865
 		assertHttpNotError(r, t)
866
-		apiWait := &docker.APIWait{}
867
-		if err := json.Unmarshal(r.Body.Bytes(), apiWait); err != nil {
866
+		var apiWait engine.Env
867
+		if err := apiWait.Decode(r.Body); err != nil {
868 868
 			t.Fatal(err)
869 869
 		}
870
-		if apiWait.StatusCode != 0 {
871
-			t.Fatalf("Non zero exit code for sleep: %d\n", apiWait.StatusCode)
870
+		if apiWait.GetInt("StatusCode") != 0 {
871
+			t.Fatalf("Non zero exit code for sleep: %d\n", apiWait.GetInt("StatusCode"))
872 872
 		}
873 873
 	})
874 874
 
... ...
@@ -1160,12 +1163,12 @@ func TestDeleteImages(t *testing.T) {
1160 1160
 		t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
1161 1161
 	}
1162 1162
 
1163
-	var outs []docker.APIRmi
1164
-	if err := json.Unmarshal(r2.Body.Bytes(), &outs); err != nil {
1163
+	outs := engine.NewTable("Created", 0)
1164
+	if _, err := outs.ReadListFrom(r2.Body.Bytes()); err != nil {
1165 1165
 		t.Fatal(err)
1166 1166
 	}
1167
-	if len(outs) != 1 {
1168
-		t.Fatalf("Expected %d event (untagged), got %d", 1, len(outs))
1167
+	if len(outs.Data) != 1 {
1168
+		t.Fatalf("Expected %d event (untagged), got %d", 1, len(outs.Data))
1169 1169
 	}
1170 1170
 	images = getImages(eng, t, false, "")
1171 1171
 
... ...
@@ -1190,14 +1193,17 @@ func TestPostContainersCopy(t *testing.T) {
1190 1190
 	containerRun(eng, containerID, t)
1191 1191
 
1192 1192
 	r := httptest.NewRecorder()
1193
-	copyData := docker.APICopy{HostPath: ".", Resource: "/test.txt"}
1194 1193
 
1195
-	jsonData, err := json.Marshal(copyData)
1196
-	if err != nil {
1194
+	var copyData engine.Env
1195
+	copyData.Set("Resource", "/test.txt")
1196
+	copyData.Set("HostPath", ".")
1197
+
1198
+	jsonData := bytes.NewBuffer(nil)
1199
+	if err := copyData.Encode(jsonData); err != nil {
1197 1200
 		t.Fatal(err)
1198 1201
 	}
1199 1202
 
1200
-	req, err := http.NewRequest("POST", "/containers/"+containerID+"/copy", bytes.NewReader(jsonData))
1203
+	req, err := http.NewRequest("POST", "/containers/"+containerID+"/copy", jsonData)
1201 1204
 	if err != nil {
1202 1205
 		t.Fatal(err)
1203 1206
 	}