summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2023-05-03 21:25:07 +0200
committerSebastiaan van Stijn <github@gone.nl>2023-05-03 21:25:07 +0200
commit66cf0e3f5575cace57219607d042cc1c4cd536d2 (patch)
treeba55bdb00f6b0bcd3e2c6f6b75099e9a27a8a199
parentdbb48e4b29e124aef6716ee8ad6856bf696235ca (diff)
downloaddocker-66cf0e3f5575cace57219607d042cc1c4cd536d2.tar.gz
client: slightly improve ContainerDiff tests
- use gotest.tools for asserting - check result returned Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
-rw-r--r--client/container_diff_test.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/client/container_diff_test.go b/client/container_diff_test.go
index 2ee8738592..6fad8767b2 100644
--- a/client/container_diff_test.go
+++ b/client/container_diff_test.go
@@ -12,6 +12,8 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
+ "gotest.tools/v3/assert"
+ is "gotest.tools/v3/assert/cmp"
)
func TestContainerDiffError(t *testing.T) {
@@ -19,28 +21,33 @@ func TestContainerDiffError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.ContainerDiff(context.Background(), "nothing")
- if !errdefs.IsSystem(err) {
- t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err)
- }
+ assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
func TestContainerDiff(t *testing.T) {
- expectedURL := "/containers/container_id/changes"
+ const expectedURL = "/containers/container_id/changes"
+
+ expected := []container.FilesystemChange{
+ {
+ Kind: container.ChangeModify,
+ Path: "/path/1",
+ },
+ {
+ Kind: container.ChangeAdd,
+ Path: "/path/2",
+ },
+ {
+ Kind: container.ChangeDelete,
+ Path: "/path/3",
+ },
+ }
+
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
- return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
+ return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
}
- b, err := json.Marshal([]container.FilesystemChange{
- {
- Kind: container.ChangeModify,
- Path: "/path/1",
- },
- {
- Kind: container.ChangeAdd,
- Path: "/path/2",
- },
- })
+ b, err := json.Marshal(expected)
if err != nil {
return nil, err
}
@@ -52,10 +59,6 @@ func TestContainerDiff(t *testing.T) {
}
changes, err := client.ContainerDiff(context.Background(), "container_id")
- if err != nil {
- t.Fatal(err)
- }
- if len(changes) != 2 {
- t.Fatalf("expected an array of 2 changes, got %v", changes)
- }
+ assert.Check(t, err)
+ assert.Check(t, is.DeepEqual(changes, expected))
}