Add unit tests for remote api

This commit is contained in:
Guillaume J. Charmes 2013-05-09 17:51:27 -07:00
parent 152ebeea43
commit ede0793d94
1 changed files with 73 additions and 57 deletions

View File

@ -156,69 +156,85 @@ func TestInfo(t *testing.T) {
} }
} }
// func TestHistory(t *testing.T) { func TestHistory(t *testing.T) {
// runtime, err := newTestRuntime() runtime, err := newTestRuntime()
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// defer nuke(runtime) defer nuke(runtime)
// srv := &Server{runtime: runtime} srv := &Server{runtime: runtime}
// req, err := http.NewRequest("GET", "/images/"+unitTestImageName+"/history", nil) body, err := getImagesHistory(srv, nil, nil, map[string]string{"name": unitTestImageName})
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// router := mux.NewRouter() history := []ApiHistory{}
// router.Path("/images/{name:.*}/history")
// vars := mux.Vars(req)
// router.
// vars["name"] = unitTestImageName
// body, err := getImagesHistory(srv, nil, req) err = json.Unmarshal(body, &history)
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// var outs []ApiHistory if len(history) != 1 {
// err = json.Unmarshal(body, &outs) t.Errorf("Excepted 1 line, %d found", len(history))
// if err != nil { }
// t.Fatal(err) }
// }
// if len(outs) != 1 {
// t.Errorf("Excepted 1 line, %d found", len(outs))
// }
// }
// func TestImagesSearch(t *testing.T) { func TestImagesSearch(t *testing.T) {
// body, _, err := call("GET", "/images/search?term=redis", nil) runtime, err := newTestRuntime()
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// var outs []ApiSearch defer nuke(runtime)
// err = json.Unmarshal(body, &outs)
// if err != nil {
// t.Fatal(err)
// }
// if len(outs) < 2 {
// t.Errorf("Excepted at least 2 lines, %d found", len(outs))
// }
// }
// func TestGetImage(t *testing.T) { srv := &Server{runtime: runtime}
// obj, _, err := call("GET", "/images/"+unitTestImageName+"/json", nil)
// if err != nil { req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
// t.Fatal(err) if err != nil {
// } t.Fatal(err)
// var out Image }
// err = json.Unmarshal(obj, &out)
// if err != nil { body, err := getImagesSearch(srv, nil, req, nil)
// t.Fatal(err) if err != nil {
// } t.Fatal(err)
// if out.Comment != "Imported from http://get.docker.io/images/busybox" { }
// t.Errorf("Error inspecting image")
// } results := []ApiSearch{}
// }
err = json.Unmarshal(body, &results)
if err != nil {
t.Fatal(err)
}
if len(results) < 2 {
t.Errorf("Excepted at least 2 lines, %d found", len(results))
}
}
func TestGetImage(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
srv := &Server{runtime: runtime}
body, err := getImagesByName(srv, nil, nil, map[string]string{"name": unitTestImageName})
if err != nil {
t.Fatal(err)
}
img := &Image{}
err = json.Unmarshal(body, img)
if err != nil {
t.Fatal(err)
}
if img.Comment != "Imported from http://get.docker.io/images/busybox" {
t.Errorf("Error inspecting image")
}
}
func TestCreateListStartStopRestartKillWaitDelete(t *testing.T) { func TestCreateListStartStopRestartKillWaitDelete(t *testing.T) {