client/service_remove_test.go
4f0d95fa
 package client // import "github.com/docker/docker/client"
7c36a1af
 
 import (
 	"bytes"
7d62e40f
 	"context"
7c36a1af
 	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
 	"testing"
 
38457285
 	"gotest.tools/assert"
 	is "gotest.tools/assert/cmp"
7c36a1af
 )
 
 func TestServiceRemoveError(t *testing.T) {
 	client := &Client{
9a072adf
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
7c36a1af
 	}
 
 	err := client.ServiceRemove(context.Background(), "service_id")
6be0f709
 	assert.Check(t, is.Error(err, "Error response from daemon: Server error"))
81bb9978
 }
 
 func TestServiceRemoveNotFoundError(t *testing.T) {
 	client := &Client{
 		client: newMockClient(errorMock(http.StatusNotFound, "missing")),
7c36a1af
 	}
81bb9978
 
 	err := client.ServiceRemove(context.Background(), "service_id")
6be0f709
 	assert.Check(t, is.Error(err, "Error: No such service: service_id"))
 	assert.Check(t, IsErrNotFound(err))
7c36a1af
 }
 
 func TestServiceRemove(t *testing.T) {
 	expectedURL := "/services/service_id"
 
 	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 != "DELETE" {
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
 			}
 			return &http.Response{
 				StatusCode: http.StatusOK,
 				Body:       ioutil.NopCloser(bytes.NewReader([]byte("body"))),
 			}, nil
 		}),
 	}
 
 	err := client.ServiceRemove(context.Background(), "service_id")
 	if err != nil {
 		t.Fatal(err)
 	}
 }