client/volume_inspect_test.go
4f0d95fa
 package client // import "github.com/docker/docker/client"
7c36a1af
 
 import (
 	"bytes"
7d62e40f
 	"context"
7c36a1af
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
 	"testing"
 
 	"github.com/docker/docker/api/types"
3e6bbefd
 	"github.com/pkg/errors"
38457285
 	"gotest.tools/assert"
 	is "gotest.tools/assert/cmp"
7c36a1af
 )
 
 func TestVolumeInspectError(t *testing.T) {
 	client := &Client{
9a072adf
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
7c36a1af
 	}
 
 	_, err := client.VolumeInspect(context.Background(), "nothing")
55bebbae
 	assert.Check(t, is.ErrorContains(err, "Error response from daemon: Server error"))
7c36a1af
 }
 
 func TestVolumeInspectNotFound(t *testing.T) {
 	client := &Client{
9a072adf
 		client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
7c36a1af
 	}
 
 	_, err := client.VolumeInspect(context.Background(), "unknown")
6be0f709
 	assert.Check(t, IsErrNotFound(err))
5ac298fd
 }
 
 func TestVolumeInspectWithEmptyID(t *testing.T) {
 	client := &Client{
 		client: newMockClient(func(req *http.Request) (*http.Response, error) {
3e6bbefd
 			return nil, errors.New("should not make request")
5ac298fd
 		}),
7c36a1af
 	}
3e6bbefd
 	_, _, err := client.VolumeInspectWithRaw(context.Background(), "")
 	if !IsErrNotFound(err) {
 		t.Fatalf("Expected NotFoundError, got %v", err)
 	}
7c36a1af
 }
 
 func TestVolumeInspect(t *testing.T) {
 	expectedURL := "/volumes/volume_id"
5ac298fd
 	expected := types.Volume{
 		Name:       "name",
 		Driver:     "driver",
 		Mountpoint: "mountpoint",
 	}
 
7c36a1af
 	client := &Client{
9a072adf
 		client: newMockClient(func(req *http.Request) (*http.Response, error) {
7c36a1af
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
 			}
 			if req.Method != "GET" {
 				return nil, fmt.Errorf("expected GET method, got %s", req.Method)
 			}
5ac298fd
 			content, err := json.Marshal(expected)
7c36a1af
 			if err != nil {
 				return nil, err
 			}
 			return &http.Response{
 				StatusCode: http.StatusOK,
 				Body:       ioutil.NopCloser(bytes.NewReader(content)),
 			}, nil
 		}),
 	}
 
5ac298fd
 	volume, err := client.VolumeInspect(context.Background(), "volume_id")
6be0f709
 	assert.NilError(t, err)
 	assert.Check(t, is.DeepEqual(expected, volume))
7c36a1af
 }