forked from fsouza/go-dockerclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_archive_test.go
51 lines (44 loc) · 1.42 KB
/
container_archive_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package docker
import (
"bytes"
"net/http"
"testing"
)
func TestUploadToContainer(t *testing.T) {
t.Parallel()
content := "File content"
in := stdinMock{bytes.NewBufferString(content)}
fakeRT := &FakeRoundTripper{status: http.StatusOK}
client := newTestClient(fakeRT)
opts := UploadToContainerOptions{
Path: "abc",
InputStream: in,
}
err := client.UploadToContainer("a123456", opts)
if err != nil {
t.Errorf("UploadToContainer: caught error %#v while uploading archive to container, expected nil", err)
}
req := fakeRT.requests[0]
if req.Method != http.MethodPut {
t.Errorf("UploadToContainer{Path:abc}: Wrong HTTP method. Want PUT. Got %s", req.Method)
}
if pathParam := req.URL.Query().Get("path"); pathParam != "abc" {
t.Errorf("ListImages({Path:abc}): Wrong parameter. Want path=abc. Got path=%s", pathParam)
}
}
func TestDownloadFromContainer(t *testing.T) {
t.Parallel()
filecontent := "File content"
client := newTestClient(&FakeRoundTripper{message: filecontent, status: http.StatusOK})
var out bytes.Buffer
opts := DownloadFromContainerOptions{
OutputStream: &out,
}
err := client.DownloadFromContainer("a123456", opts)
if err != nil {
t.Errorf("DownloadFromContainer: caught error %#v while downloading from container, expected nil", err.Error())
}
if out.String() != filecontent {
t.Errorf("DownloadFromContainer: wrong stdout. Want %#v. Got %#v.", filecontent, out.String())
}
}