File: container_changes_test.go

package info (click to toggle)
golang-github-fsouza-go-dockerclient 1.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,180 kB
  • sloc: makefile: 26
file content (70 lines) | stat: -rw-r--r-- 1,961 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package docker

import (
	"encoding/json"
	"net/http"
	"net/url"
	"reflect"
	"testing"
)

func TestContainerChanges(t *testing.T) {
	t.Parallel()
	jsonChanges := `[
     {
             "Path":"/dev",
             "Kind":0
     },
     {
             "Path":"/dev/kmsg",
             "Kind":1
     },
     {
             "Path":"/test",
             "Kind":1
     }
]`
	var expected []Change
	err := json.Unmarshal([]byte(jsonChanges), &expected)
	if err != nil {
		t.Fatal(err)
	}
	fakeRT := &FakeRoundTripper{message: jsonChanges, status: http.StatusOK}
	client := newTestClient(fakeRT)
	id := "4fa6e0f0c678"
	changes, err := client.ContainerChanges(id)
	if err != nil {
		t.Fatal(err)
	}
	if !reflect.DeepEqual(changes, expected) {
		t.Errorf("ContainerChanges(%q): Expected %#v. Got %#v.", id, expected, changes)
	}
	expectedURL, _ := url.Parse(client.getURL("/containers/4fa6e0f0c678/changes"))
	if gotPath := fakeRT.requests[0].URL.Path; gotPath != expectedURL.Path {
		t.Errorf("ContainerChanges(%q): Wrong path in request. Want %q. Got %q.", id, expectedURL.Path, gotPath)
	}
}

func TestContainerChangesFailure(t *testing.T) {
	t.Parallel()
	client := newTestClient(&FakeRoundTripper{message: "server error", status: 500})
	expected := Error{Status: 500, Message: "server error"}
	changes, err := client.ContainerChanges("abe033")
	if changes != nil {
		t.Errorf("ContainerChanges: Expected <nil> changes, got %#v", changes)
	}
	if !reflect.DeepEqual(expected, *err.(*Error)) {
		t.Errorf("ContainerChanges: Wrong error information. Want %#v. Got %#v.", expected, err)
	}
}

func TestContainerChangesNotFound(t *testing.T) {
	t.Parallel()
	const containerID = "abe033"
	client := newTestClient(&FakeRoundTripper{message: "no such container", status: 404})
	changes, err := client.ContainerChanges(containerID)
	if changes != nil {
		t.Errorf("ContainerChanges: Expected <nil> changes, got %#v", changes)
	}
	expectNoSuchContainer(t, containerID, err)
}