plugin_remove_test.go 1.2 KB

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