forked from fsouza/go-dockerclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_remove_test.go
53 lines (49 loc) · 1.69 KB
/
container_remove_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
53
package docker
import (
"net/http"
"net/url"
"reflect"
"testing"
)
func TestRemoveContainer(t *testing.T) {
t.Parallel()
fakeRT := &FakeRoundTripper{message: "", status: http.StatusOK}
client := newTestClient(fakeRT)
id := "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2"
opts := RemoveContainerOptions{ID: id}
err := client.RemoveContainer(opts)
if err != nil {
t.Fatal(err)
}
req := fakeRT.requests[0]
if req.Method != http.MethodDelete {
t.Errorf("RemoveContainer(%q): wrong HTTP method. Want %q. Got %q.", id, http.MethodDelete, req.Method)
}
expectedURL, _ := url.Parse(client.getURL("/containers/" + id))
if gotPath := req.URL.Path; gotPath != expectedURL.Path {
t.Errorf("RemoveContainer(%q): Wrong path in request. Want %q. Got %q.", id, expectedURL.Path, gotPath)
}
}
func TestRemoveContainerRemoveVolumes(t *testing.T) {
t.Parallel()
fakeRT := &FakeRoundTripper{message: "", status: http.StatusOK}
client := newTestClient(fakeRT)
id := "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2"
opts := RemoveContainerOptions{ID: id, RemoveVolumes: true}
err := client.RemoveContainer(opts)
if err != nil {
t.Fatal(err)
}
req := fakeRT.requests[0]
params := map[string][]string(req.URL.Query())
expected := map[string][]string{"v": {"1"}}
if !reflect.DeepEqual(params, expected) {
t.Errorf("RemoveContainer(%q): wrong parameters. Want %#v. Got %#v.", id, expected, params)
}
}
func TestRemoveContainerNotFound(t *testing.T) {
t.Parallel()
client := newTestClient(&FakeRoundTripper{message: "no such container", status: http.StatusNotFound})
err := client.RemoveContainer(RemoveContainerOptions{ID: "a2334"})
expectNoSuchContainer(t, "a2334", err)
}