plugin_set_test.go 1.1 KB

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