plugin_enable_test.go 1.3 KB

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