plugin_inspect_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package client
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. "strings"
  9. "testing"
  10. "github.com/docker/docker/api/types"
  11. "golang.org/x/net/context"
  12. )
  13. func TestPluginInspectError(t *testing.T) {
  14. client := &Client{
  15. client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
  16. }
  17. _, _, err := client.PluginInspectWithRaw(context.Background(), "nothing")
  18. if err == nil || err.Error() != "Error response from daemon: Server error" {
  19. t.Fatalf("expected a Server Error, got %v", err)
  20. }
  21. }
  22. func TestPluginInspect(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. content, err := json.Marshal(types.Plugin{
  30. ID: "plugin_id",
  31. })
  32. if err != nil {
  33. return nil, err
  34. }
  35. return &http.Response{
  36. StatusCode: http.StatusOK,
  37. Body: ioutil.NopCloser(bytes.NewReader(content)),
  38. }, nil
  39. }),
  40. }
  41. pluginInspect, _, err := client.PluginInspectWithRaw(context.Background(), "plugin_name")
  42. if err != nil {
  43. t.Fatal(err)
  44. }
  45. if pluginInspect.ID != "plugin_id" {
  46. t.Fatalf("expected `plugin_id`, got %s", pluginInspect.ID)
  47. }
  48. }