Browse code

Update the unit tests to reflect the new API

Guillaume J. Charmes authored on 2013/04/25 07:35:28
Showing 3 changed files
... ...
@@ -339,7 +339,7 @@ func TestAttachDisconnect(t *testing.T) {
339 339
 
340 340
 	srv := &Server{runtime: runtime}
341 341
 
342
-	container, err := runtime.Create(
342
+	container, err := NewBuilder(runtime).Create(
343 343
 		&Config{
344 344
 			Image:     GetTestImage(runtime).Id,
345 345
 			Memory:    33554432,
... ...
@@ -20,7 +20,7 @@ func TestIdFormat(t *testing.T) {
20 20
 		t.Fatal(err)
21 21
 	}
22 22
 	defer nuke(runtime)
23
-	container1, err := runtime.Create(
23
+	container1, err := NewBuilder(runtime).Create(
24 24
 		&Config{
25 25
 			Image: GetTestImage(runtime).Id,
26 26
 			Cmd:   []string{"/bin/sh", "-c", "echo hello world"},
... ...
@@ -44,7 +44,7 @@ func TestMultipleAttachRestart(t *testing.T) {
44 44
 		t.Fatal(err)
45 45
 	}
46 46
 	defer nuke(runtime)
47
-	container, err := runtime.Create(
47
+	container, err := NewBuilder(runtime).Create(
48 48
 		&Config{
49 49
 			Image: GetTestImage(runtime).Id,
50 50
 			Cmd: []string{"/bin/sh", "-c",
... ...
@@ -148,8 +148,10 @@ func TestDiff(t *testing.T) {
148 148
 	}
149 149
 	defer nuke(runtime)
150 150
 
151
+	builder := NewBuilder(runtime)
152
+
151 153
 	// Create a container and remove a file
152
-	container1, err := runtime.Create(
154
+	container1, err := builder.Create(
153 155
 		&Config{
154 156
 			Image: GetTestImage(runtime).Id,
155 157
 			Cmd:   []string{"/bin/rm", "/etc/passwd"},
... ...
@@ -190,7 +192,7 @@ func TestDiff(t *testing.T) {
190 190
 	}
191 191
 
192 192
 	// Create a new container from the commited image
193
-	container2, err := runtime.Create(
193
+	container2, err := builder.Create(
194 194
 		&Config{
195 195
 			Image: img.Id,
196 196
 			Cmd:   []string{"cat", "/etc/passwd"},
... ...
@@ -301,7 +303,10 @@ func TestCommitRun(t *testing.T) {
301 301
 		t.Fatal(err)
302 302
 	}
303 303
 	defer nuke(runtime)
304
-	container1, err := runtime.Create(
304
+
305
+	builder := NewBuilder(runtime)
306
+
307
+	container1, err := builder.Create(
305 308
 		&Config{
306 309
 			Image: GetTestImage(runtime).Id,
307 310
 			Cmd:   []string{"/bin/sh", "-c", "echo hello > /world"},
... ...
@@ -333,7 +338,7 @@ func TestCommitRun(t *testing.T) {
333 333
 
334 334
 	// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
335 335
 
336
-	container2, err := runtime.Create(
336
+	container2, err := builder.Create(
337 337
 		&Config{
338 338
 			Image: img.Id,
339 339
 			Cmd:   []string{"cat", "/world"},
... ...
@@ -380,7 +385,7 @@ func TestStart(t *testing.T) {
380 380
 		t.Fatal(err)
381 381
 	}
382 382
 	defer nuke(runtime)
383
-	container, err := runtime.Create(
383
+	container, err := NewBuilder(runtime).Create(
384 384
 		&Config{
385 385
 			Image:     GetTestImage(runtime).Id,
386 386
 			Memory:    33554432,
... ...
@@ -419,7 +424,7 @@ func TestRun(t *testing.T) {
419 419
 		t.Fatal(err)
420 420
 	}
421 421
 	defer nuke(runtime)
422
-	container, err := runtime.Create(
422
+	container, err := NewBuilder(runtime).Create(
423 423
 		&Config{
424 424
 			Image: GetTestImage(runtime).Id,
425 425
 			Cmd:   []string{"ls", "-al"},
... ...
@@ -447,7 +452,7 @@ func TestOutput(t *testing.T) {
447 447
 		t.Fatal(err)
448 448
 	}
449 449
 	defer nuke(runtime)
450
-	container, err := runtime.Create(
450
+	container, err := NewBuilder(runtime).Create(
451 451
 		&Config{
452 452
 			Image: GetTestImage(runtime).Id,
453 453
 			Cmd:   []string{"echo", "-n", "foobar"},
... ...
@@ -472,7 +477,7 @@ func TestKillDifferentUser(t *testing.T) {
472 472
 		t.Fatal(err)
473 473
 	}
474 474
 	defer nuke(runtime)
475
-	container, err := runtime.Create(&Config{
475
+	container, err := NewBuilder(runtime).Create(&Config{
476 476
 		Image: GetTestImage(runtime).Id,
477 477
 		Cmd:   []string{"tail", "-f", "/etc/resolv.conf"},
478 478
 		User:  "daemon",
... ...
@@ -520,7 +525,7 @@ func TestKill(t *testing.T) {
520 520
 		t.Fatal(err)
521 521
 	}
522 522
 	defer nuke(runtime)
523
-	container, err := runtime.Create(&Config{
523
+	container, err := NewBuilder(runtime).Create(&Config{
524 524
 		Image: GetTestImage(runtime).Id,
525 525
 		Cmd:   []string{"cat", "/dev/zero"},
526 526
 	},
... ...
@@ -566,7 +571,9 @@ func TestExitCode(t *testing.T) {
566 566
 	}
567 567
 	defer nuke(runtime)
568 568
 
569
-	trueContainer, err := runtime.Create(&Config{
569
+	builder := NewBuilder(runtime)
570
+
571
+	trueContainer, err := builder.Create(&Config{
570 572
 		Image: GetTestImage(runtime).Id,
571 573
 		Cmd:   []string{"/bin/true", ""},
572 574
 	})
... ...
@@ -581,7 +588,7 @@ func TestExitCode(t *testing.T) {
581 581
 		t.Errorf("Unexpected exit code %d (expected 0)", trueContainer.State.ExitCode)
582 582
 	}
583 583
 
584
-	falseContainer, err := runtime.Create(&Config{
584
+	falseContainer, err := builder.Create(&Config{
585 585
 		Image: GetTestImage(runtime).Id,
586 586
 		Cmd:   []string{"/bin/false", ""},
587 587
 	})
... ...
@@ -603,7 +610,7 @@ func TestRestart(t *testing.T) {
603 603
 		t.Fatal(err)
604 604
 	}
605 605
 	defer nuke(runtime)
606
-	container, err := runtime.Create(&Config{
606
+	container, err := NewBuilder(runtime).Create(&Config{
607 607
 		Image: GetTestImage(runtime).Id,
608 608
 		Cmd:   []string{"echo", "-n", "foobar"},
609 609
 	},
... ...
@@ -636,7 +643,7 @@ func TestRestartStdin(t *testing.T) {
636 636
 		t.Fatal(err)
637 637
 	}
638 638
 	defer nuke(runtime)
639
-	container, err := runtime.Create(&Config{
639
+	container, err := NewBuilder(runtime).Create(&Config{
640 640
 		Image: GetTestImage(runtime).Id,
641 641
 		Cmd:   []string{"cat"},
642 642
 
... ...
@@ -715,8 +722,10 @@ func TestUser(t *testing.T) {
715 715
 	}
716 716
 	defer nuke(runtime)
717 717
 
718
+	builder := NewBuilder(runtime)
719
+
718 720
 	// Default user must be root
719
-	container, err := runtime.Create(&Config{
721
+	container, err := builder.Create(&Config{
720 722
 		Image: GetTestImage(runtime).Id,
721 723
 		Cmd:   []string{"id"},
722 724
 	},
... ...
@@ -734,7 +743,7 @@ func TestUser(t *testing.T) {
734 734
 	}
735 735
 
736 736
 	// Set a username
737
-	container, err = runtime.Create(&Config{
737
+	container, err = builder.Create(&Config{
738 738
 		Image: GetTestImage(runtime).Id,
739 739
 		Cmd:   []string{"id"},
740 740
 
... ...
@@ -754,7 +763,7 @@ func TestUser(t *testing.T) {
754 754
 	}
755 755
 
756 756
 	// Set a UID
757
-	container, err = runtime.Create(&Config{
757
+	container, err = builder.Create(&Config{
758 758
 		Image: GetTestImage(runtime).Id,
759 759
 		Cmd:   []string{"id"},
760 760
 
... ...
@@ -774,7 +783,7 @@ func TestUser(t *testing.T) {
774 774
 	}
775 775
 
776 776
 	// Set a different user by uid
777
-	container, err = runtime.Create(&Config{
777
+	container, err = builder.Create(&Config{
778 778
 		Image: GetTestImage(runtime).Id,
779 779
 		Cmd:   []string{"id"},
780 780
 
... ...
@@ -796,7 +805,7 @@ func TestUser(t *testing.T) {
796 796
 	}
797 797
 
798 798
 	// Set a different user by username
799
-	container, err = runtime.Create(&Config{
799
+	container, err = builder.Create(&Config{
800 800
 		Image: GetTestImage(runtime).Id,
801 801
 		Cmd:   []string{"id"},
802 802
 
... ...
@@ -823,7 +832,9 @@ func TestMultipleContainers(t *testing.T) {
823 823
 	}
824 824
 	defer nuke(runtime)
825 825
 
826
-	container1, err := runtime.Create(&Config{
826
+	builder := NewBuilder(runtime)
827
+
828
+	container1, err := builder.Create(&Config{
827 829
 		Image: GetTestImage(runtime).Id,
828 830
 		Cmd:   []string{"cat", "/dev/zero"},
829 831
 	},
... ...
@@ -833,7 +844,7 @@ func TestMultipleContainers(t *testing.T) {
833 833
 	}
834 834
 	defer runtime.Destroy(container1)
835 835
 
836
-	container2, err := runtime.Create(&Config{
836
+	container2, err := builder.Create(&Config{
837 837
 		Image: GetTestImage(runtime).Id,
838 838
 		Cmd:   []string{"cat", "/dev/zero"},
839 839
 	},
... ...
@@ -879,7 +890,7 @@ func TestStdin(t *testing.T) {
879 879
 		t.Fatal(err)
880 880
 	}
881 881
 	defer nuke(runtime)
882
-	container, err := runtime.Create(&Config{
882
+	container, err := NewBuilder(runtime).Create(&Config{
883 883
 		Image: GetTestImage(runtime).Id,
884 884
 		Cmd:   []string{"cat"},
885 885
 
... ...
@@ -926,7 +937,7 @@ func TestTty(t *testing.T) {
926 926
 		t.Fatal(err)
927 927
 	}
928 928
 	defer nuke(runtime)
929
-	container, err := runtime.Create(&Config{
929
+	container, err := NewBuilder(runtime).Create(&Config{
930 930
 		Image: GetTestImage(runtime).Id,
931 931
 		Cmd:   []string{"cat"},
932 932
 
... ...
@@ -973,7 +984,7 @@ func TestEnv(t *testing.T) {
973 973
 		t.Fatal(err)
974 974
 	}
975 975
 	defer nuke(runtime)
976
-	container, err := runtime.Create(&Config{
976
+	container, err := NewBuilder(runtime).Create(&Config{
977 977
 		Image: GetTestImage(runtime).Id,
978 978
 		Cmd:   []string{"/usr/bin/env"},
979 979
 	},
... ...
@@ -1047,7 +1058,7 @@ func TestLXCConfig(t *testing.T) {
1047 1047
 	memMin := 33554432
1048 1048
 	memMax := 536870912
1049 1049
 	mem := memMin + rand.Intn(memMax-memMin)
1050
-	container, err := runtime.Create(&Config{
1050
+	container, err := NewBuilder(runtime).Create(&Config{
1051 1051
 		Image: GetTestImage(runtime).Id,
1052 1052
 		Cmd:   []string{"/bin/true"},
1053 1053
 
... ...
@@ -1074,7 +1085,7 @@ func BenchmarkRunSequencial(b *testing.B) {
1074 1074
 	}
1075 1075
 	defer nuke(runtime)
1076 1076
 	for i := 0; i < b.N; i++ {
1077
-		container, err := runtime.Create(&Config{
1077
+		container, err := NewBuilder(runtime).Create(&Config{
1078 1078
 			Image: GetTestImage(runtime).Id,
1079 1079
 			Cmd:   []string{"echo", "-n", "foo"},
1080 1080
 		},
... ...
@@ -1109,7 +1120,7 @@ func BenchmarkRunParallel(b *testing.B) {
1109 1109
 		complete := make(chan error)
1110 1110
 		tasks = append(tasks, complete)
1111 1111
 		go func(i int, complete chan error) {
1112
-			container, err := runtime.Create(&Config{
1112
+			container, err := NewBuilder(runtime).Create(&Config{
1113 1113
 				Image: GetTestImage(runtime).Id,
1114 1114
 				Cmd:   []string{"echo", "-n", "foo"},
1115 1115
 			},
... ...
@@ -118,7 +118,7 @@ func TestRuntimeCreate(t *testing.T) {
118 118
 	if len(runtime.List()) != 0 {
119 119
 		t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
120 120
 	}
121
-	container, err := runtime.Create(&Config{
121
+	container, err := NewBuilder(runtime).Create(&Config{
122 122
 		Image: GetTestImage(runtime).Id,
123 123
 		Cmd:   []string{"ls", "-al"},
124 124
 	},
... ...
@@ -165,7 +165,7 @@ func TestDestroy(t *testing.T) {
165 165
 		t.Fatal(err)
166 166
 	}
167 167
 	defer nuke(runtime)
168
-	container, err := runtime.Create(&Config{
168
+	container, err := NewBuilder(runtime).Create(&Config{
169 169
 		Image: GetTestImage(runtime).Id,
170 170
 		Cmd:   []string{"ls", "-al"},
171 171
 	},
... ...
@@ -212,7 +212,10 @@ func TestGet(t *testing.T) {
212 212
 		t.Fatal(err)
213 213
 	}
214 214
 	defer nuke(runtime)
215
-	container1, err := runtime.Create(&Config{
215
+
216
+	builder := NewBuilder(runtime)
217
+
218
+	container1, err := builder.Create(&Config{
216 219
 		Image: GetTestImage(runtime).Id,
217 220
 		Cmd:   []string{"ls", "-al"},
218 221
 	},
... ...
@@ -222,7 +225,7 @@ func TestGet(t *testing.T) {
222 222
 	}
223 223
 	defer runtime.Destroy(container1)
224 224
 
225
-	container2, err := runtime.Create(&Config{
225
+	container2, err := builder.Create(&Config{
226 226
 		Image: GetTestImage(runtime).Id,
227 227
 		Cmd:   []string{"ls", "-al"},
228 228
 	},
... ...
@@ -232,7 +235,7 @@ func TestGet(t *testing.T) {
232 232
 	}
233 233
 	defer runtime.Destroy(container2)
234 234
 
235
-	container3, err := runtime.Create(&Config{
235
+	container3, err := builder.Create(&Config{
236 236
 		Image: GetTestImage(runtime).Id,
237 237
 		Cmd:   []string{"ls", "-al"},
238 238
 	},
... ...
@@ -262,7 +265,7 @@ func TestAllocatePortLocalhost(t *testing.T) {
262 262
 	if err != nil {
263 263
 		t.Fatal(err)
264 264
 	}
265
-	container, err := runtime.Create(&Config{
265
+	container, err := NewBuilder(runtime).Create(&Config{
266 266
 		Image:     GetTestImage(runtime).Id,
267 267
 		Cmd:       []string{"sh", "-c", "echo well hello there | nc -l -p 5555"},
268 268
 		PortSpecs: []string{"5555"},
... ...
@@ -325,8 +328,10 @@ func TestRestore(t *testing.T) {
325 325
 		t.Fatal(err)
326 326
 	}
327 327
 
328
+	builder := NewBuilder(runtime1)
329
+
328 330
 	// Create a container with one instance of docker
329
-	container1, err := runtime1.Create(&Config{
331
+	container1, err := builder.Create(&Config{
330 332
 		Image: GetTestImage(runtime1).Id,
331 333
 		Cmd:   []string{"ls", "-al"},
332 334
 	},
... ...
@@ -337,7 +342,7 @@ func TestRestore(t *testing.T) {
337 337
 	defer runtime1.Destroy(container1)
338 338
 
339 339
 	// Create a second container meant to be killed
340
-	container2, err := runtime1.Create(&Config{
340
+	container2, err := builder.Create(&Config{
341 341
 		Image:     GetTestImage(runtime1).Id,
342 342
 		Cmd:       []string{"/bin/cat"},
343 343
 		OpenStdin: true,