forked from fsouza/go-dockerclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_copy_test.go
52 lines (48 loc) · 1.53 KB
/
container_copy_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
52
package docker
import (
"bytes"
"net/http"
"testing"
)
func TestCopyFromContainer(t *testing.T) {
t.Parallel()
content := "File content"
out := stdoutMock{bytes.NewBufferString(content)}
client := newTestClient(&FakeRoundTripper{status: http.StatusOK})
opts := CopyFromContainerOptions{
Container: "a123456",
OutputStream: &out,
}
err := client.CopyFromContainer(opts)
if err != nil {
t.Errorf("CopyFromContainer: caught error %#v while copying from container, expected nil", err.Error())
}
if out.String() != content {
t.Errorf("CopyFromContainer: wrong stdout. Want %#v. Got %#v.", content, out.String())
}
}
func TestCopyFromContainerEmptyContainer(t *testing.T) {
t.Parallel()
client := newTestClient(&FakeRoundTripper{status: http.StatusOK})
err := client.CopyFromContainer(CopyFromContainerOptions{})
_, ok := err.(*NoSuchContainer)
if !ok {
t.Errorf("CopyFromContainer: invalid error returned. Want NoSuchContainer, got %#v.", err)
}
}
func TestCopyFromContainerDockerAPI124(t *testing.T) {
t.Parallel()
client := newTestClient(&FakeRoundTripper{status: http.StatusOK})
client.serverAPIVersion = apiVersion124
opts := CopyFromContainerOptions{
Container: "a123456",
}
err := client.CopyFromContainer(opts)
if err == nil {
t.Fatal("got unexpected <nil> error")
}
expectedMsg := "go-dockerclient: CopyFromContainer is no longer available in Docker >= 1.12, use DownloadFromContainer instead"
if err.Error() != expectedMsg {
t.Errorf("wrong error message\nWant %q\nGot %q", expectedMsg, err.Error())
}
}