client/container_diff_test.go
7c36a1af
 package client
 
 import (
 	"bytes"
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
 	"testing"
 
b83d9bf6
 	"github.com/docker/docker/api/types/container"
7c36a1af
 	"golang.org/x/net/context"
 )
 
 func TestContainerDiffError(t *testing.T) {
 	client := &Client{
9a072adf
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
7c36a1af
 	}
 	_, err := client.ContainerDiff(context.Background(), "nothing")
 	if err == nil || err.Error() != "Error response from daemon: Server error" {
 		t.Fatalf("expected a Server Error, got %v", err)
 	}
 
 }
 
 func TestContainerDiff(t *testing.T) {
 	expectedURL := "/containers/container_id/changes"
 	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)
 			}
b83d9bf6
 			b, err := json.Marshal([]container.ContainerChangeResponseItem{
7c36a1af
 				{
 					Kind: 0,
 					Path: "/path/1",
 				},
 				{
 					Kind: 1,
 					Path: "/path/2",
 				},
 			})
 			if err != nil {
 				return nil, err
 			}
 			return &http.Response{
 				StatusCode: http.StatusOK,
 				Body:       ioutil.NopCloser(bytes.NewReader(b)),
 			}, nil
 		}),
 	}
 
 	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)
 	}
 }