github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/plugin_set_test.go (about)

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