plugin_remove_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package client
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "strings"
  8. "testing"
  9. "github.com/docker/docker/api/types"
  10. "golang.org/x/net/context"
  11. )
  12. func TestPluginRemoveError(t *testing.T) {
  13. client := &Client{
  14. client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
  15. }
  16. err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{})
  17. if err == nil || err.Error() != "Error response from daemon: Server error" {
  18. t.Fatalf("expected a Server Error, got %v", err)
  19. }
  20. }
  21. func TestPluginRemove(t *testing.T) {
  22. expectedURL := "/plugins/plugin_name"
  23. client := &Client{
  24. client: newMockClient(func(req *http.Request) (*http.Response, error) {
  25. if !strings.HasPrefix(req.URL.Path, expectedURL) {
  26. return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
  27. }
  28. if req.Method != "DELETE" {
  29. return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
  30. }
  31. return &http.Response{
  32. StatusCode: http.StatusOK,
  33. Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
  34. }, nil
  35. }),
  36. }
  37. err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{})
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. }