Browse code

fix tests

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

Victor Vieux authored on 2014/06/25 10:44:48
Showing 1 changed files
... ...
@@ -697,21 +697,24 @@ func TestPostContainersStart(t *testing.T) {
697 697
 	}
698 698
 
699 699
 	containerAssertExists(eng, containerID, t)
700
-	// Give some time to the process to start
701
-	// FIXME: use Wait once it's available as a job
702
-	containerWaitTimeout(eng, containerID, t)
703
-	if !containerRunning(eng, containerID, t) {
704
-		t.Errorf("Container should be running")
700
+
701
+	req, err = http.NewRequest("POST", "/containers/"+containerID+"/start", bytes.NewReader(hostConfigJSON))
702
+	if err != nil {
703
+		t.Fatal(err)
705 704
 	}
706 705
 
706
+	req.Header.Set("Content-Type", "application/json")
707
+
707 708
 	r = httptest.NewRecorder()
708 709
 	if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
709 710
 		t.Fatal(err)
710 711
 	}
711
-	// Starting an already started container should return an error
712
-	// FIXME: verify a precise error code. There is a possible bug here
713
-	// which causes this to return 404 even though the container exists.
714
-	assertHttpError(r, t)
712
+
713
+	// Starting an already started container should return a 304
714
+	assertHttpNotError(r, t)
715
+	if r.Code != http.StatusNotModified {
716
+		t.Fatalf("%d NOT MODIFIER expected, received %d\n", http.StatusNotModified, r.Code)
717
+	}
715 718
 	containerAssertExists(eng, containerID, t)
716 719
 	containerKill(eng, containerID, t)
717 720
 }
... ...
@@ -790,6 +793,22 @@ func TestPostContainersStop(t *testing.T) {
790 790
 	if containerRunning(eng, containerID, t) {
791 791
 		t.Fatalf("The container hasn't been stopped")
792 792
 	}
793
+
794
+	req, err = http.NewRequest("POST", "/containers/"+containerID+"/stop?t=1", bytes.NewReader([]byte{}))
795
+	if err != nil {
796
+		t.Fatal(err)
797
+	}
798
+
799
+	r = httptest.NewRecorder()
800
+	if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
801
+		t.Fatal(err)
802
+	}
803
+
804
+	// Stopping an already stopper container should return a 304
805
+	assertHttpNotError(r, t)
806
+	if r.Code != http.StatusNotModified {
807
+		t.Fatalf("%d NOT MODIFIER expected, received %d\n", http.StatusNotModified, r.Code)
808
+	}
793 809
 }
794 810
 
795 811
 func TestPostContainersWait(t *testing.T) {