mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
More unit tests for remote api
This commit is contained in:
parent
28fd289b44
commit
310fec4819
1 changed files with 47 additions and 15 deletions
62
api_test.go
62
api_test.go
|
@ -1,9 +1,12 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/dotcloud/docker/auth"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -270,24 +273,53 @@ func TestGetContainersExport(t *testing.T) {
|
|||
t.Log("Test not implemented")
|
||||
}
|
||||
|
||||
func TestGetContainerChanges(t *testing.T) {
|
||||
// FIXME: Implement this test
|
||||
t.Log("Test on implemented")
|
||||
// r := httptest.NewRecorder()
|
||||
func TestGetContainersChanges(t *testing.T) {
|
||||
runtime, err := newTestRuntime()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(runtime)
|
||||
|
||||
// req, err := http.NewRequest("GET", "/containers/"+id+"/changes", nil)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
srv := &Server{runtime: runtime}
|
||||
|
||||
// body, err := getContainersChanges(srv, r, req, nil)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
builder := NewBuilder(runtime)
|
||||
|
||||
// if body == nil {
|
||||
// t.Fatalf("Body expected, received: nil\n")
|
||||
// }
|
||||
// Create a container and remove a file
|
||||
container, err := builder.Create(
|
||||
&Config{
|
||||
Image: GetTestImage(runtime).Id,
|
||||
Cmd: []string{"/bin/rm", "/etc/passwd"},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer runtime.Destroy(container)
|
||||
|
||||
if err := container.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
body, err := getContainersChanges(srv, nil, nil, map[string]string{"name": container.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
changes := []Change{}
|
||||
if err := json.Unmarshal(body, &changes); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Check the changelog
|
||||
success := false
|
||||
for _, elem := range changes {
|
||||
if elem.Path == "/etc/passwd" && elem.Kind == 2 {
|
||||
success = true
|
||||
}
|
||||
}
|
||||
if !success {
|
||||
t.Fatalf("/etc/passwd as been removed but is not present in the diff")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetContainersByName(t *testing.T) {
|
||||
//FIXME: Implement this test
|
||||
|
|
Loading…
Reference in a new issue