1
0
mirror of https://github.com/rancher/os.git synced 2025-09-20 18:13:35 +00:00

Godeps updates

This commit is contained in:
Darren Shepherd
2015-03-14 21:32:32 -07:00
parent 7baf6fc74c
commit 7dc4df73cb
5 changed files with 64 additions and 4 deletions

2
Godeps/Godeps.json generated
View File

@@ -180,7 +180,7 @@
},
{
"ImportPath": "github.com/fsouza/go-dockerclient",
"Rev": "96713c2fd1829362fa590fec24594e0c115ce64b"
"Rev": "73a0e3760037ce30d63015a74af4ffe48329dbf8"
},
{
"ImportPath": "github.com/guelfey/go.dbus",

View File

@@ -406,7 +406,7 @@ func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
path := "/containers/" + id + "/start"
_, status, err := c.do("POST", path, hostConfig, true)
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
return &NoSuchContainer{ID: id, Err: err}
}
if status == http.StatusNotModified {
return &ContainerAlreadyRunning{ID: id}
@@ -768,9 +768,13 @@ func (c *Client) ExportContainer(opts ExportContainerOptions) error {
// NoSuchContainer is the error returned when a given container does not exist.
type NoSuchContainer struct {
ID string
Err error
}
func (err *NoSuchContainer) Error() string {
if err.Err != nil {
return err.Err.Error()
}
return "No such container: " + err.ID
}

View File

@@ -7,6 +7,7 @@ package docker
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net"
"net/http"
@@ -536,7 +537,7 @@ func TestStartContainerNilHostConfig(t *testing.T) {
func TestStartContainerNotFound(t *testing.T) {
client := newTestClient(&FakeRoundTripper{message: "no such container", status: http.StatusNotFound})
err := client.StartContainer("a2344", &HostConfig{})
expected := &NoSuchContainer{ID: "a2344"}
expected := &NoSuchContainer{ID: "a2344", Err: err.(*NoSuchContainer).Err}
if !reflect.DeepEqual(err, expected) {
t.Errorf("StartContainer: Wrong error returned. Want %#v. Got %#v.", expected, err)
}
@@ -1307,6 +1308,14 @@ func TestNoSuchContainerError(t *testing.T) {
}
}
func TestNoSuchContainerErrorMessage(t *testing.T) {
var err = &NoSuchContainer{ID: "i345", Err: errors.New("some advanced error info")}
expected := "some advanced error info"
if got := err.Error(); got != expected {
t.Errorf("NoSuchContainer: wrong message. Want %q. Got %q.", expected, got)
}
}
func TestExportContainer(t *testing.T) {
content := "exported container tar content"
out := stdoutMock{bytes.NewBufferString(content)}

View File

@@ -92,6 +92,7 @@ func (s *DockerServer) buildMuxer() {
s.mux.Path("/containers/json").Methods("GET").HandlerFunc(s.handlerWrapper(s.listContainers))
s.mux.Path("/containers/create").Methods("POST").HandlerFunc(s.handlerWrapper(s.createContainer))
s.mux.Path("/containers/{id:.*}/json").Methods("GET").HandlerFunc(s.handlerWrapper(s.inspectContainer))
s.mux.Path("/containers/{id:.*}/rename").Methods("POST").HandlerFunc(s.handlerWrapper(s.renameContainer))
s.mux.Path("/containers/{id:.*}/top").Methods("GET").HandlerFunc(s.handlerWrapper(s.topContainer))
s.mux.Path("/containers/{id:.*}/start").Methods("POST").HandlerFunc(s.handlerWrapper(s.startContainer))
s.mux.Path("/containers/{id:.*}/kill").Methods("POST").HandlerFunc(s.handlerWrapper(s.stopContainer))
@@ -372,6 +373,23 @@ func (s *DockerServer) generateID() string {
return fmt.Sprintf("%x", buf)
}
func (s *DockerServer) renameContainer(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
container, index, err := s.findContainer(id)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
copy := *container
copy.Name = r.URL.Query().Get("name")
s.cMut.Lock()
defer s.cMut.Unlock()
if s.containers[index].ID == copy.ID {
s.containers[index] = &copy
}
w.WriteHeader(http.StatusNoContent)
}
func (s *DockerServer) inspectContainer(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
container, _, err := s.findContainer(id)

View File

@@ -255,6 +255,35 @@ func TestCreateContainerImageNotFound(t *testing.T) {
}
}
func TestRenameContainer(t *testing.T) {
server := DockerServer{}
addContainers(&server, 2)
server.buildMuxer()
recorder := httptest.NewRecorder()
newName := server.containers[0].Name + "abc"
path := fmt.Sprintf("/containers/%s/rename?name=%s", server.containers[0].ID, newName)
request, _ := http.NewRequest("POST", path, nil)
server.ServeHTTP(recorder, request)
if recorder.Code != http.StatusNoContent {
t.Errorf("RenameContainer: wrong status. Want %d. Got %d.", http.StatusNoContent, recorder.Code)
}
container := server.containers[0]
if container.Name != newName {
t.Errorf("RenameContainer: did not rename the container. Want %q. Got %q.", newName, container.Name)
}
}
func TestRenameContainerNotFound(t *testing.T) {
server := DockerServer{}
server.buildMuxer()
recorder := httptest.NewRecorder()
request, _ := http.NewRequest("POST", "/containers/blabla/rename?name=something", nil)
server.ServeHTTP(recorder, request)
if recorder.Code != http.StatusNotFound {
t.Errorf("RenameContainer: wrong status. Want %d. Got %d.", http.StatusNotFound, recorder.Code)
}
}
func TestCommitContainer(t *testing.T) {
server := DockerServer{}
addContainers(&server, 2)