github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/client/plugin_set_test.go (about) 1 package client // import "github.com/Prakhar-Agarwal-byte/moby/client" 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 "net/http" 9 "strings" 10 "testing" 11 12 "github.com/Prakhar-Agarwal-byte/moby/errdefs" 13 "gotest.tools/v3/assert" 14 is "gotest.tools/v3/assert/cmp" 15 ) 16 17 func TestPluginSetError(t *testing.T) { 18 client := &Client{ 19 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 20 } 21 22 err := client.PluginSet(context.Background(), "plugin_name", []string{}) 23 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 24 } 25 26 func TestPluginSet(t *testing.T) { 27 expectedURL := "/plugins/plugin_name/set" 28 29 client := &Client{ 30 client: newMockClient(func(req *http.Request) (*http.Response, error) { 31 if !strings.HasPrefix(req.URL.Path, expectedURL) { 32 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 33 } 34 if req.Method != http.MethodPost { 35 return nil, fmt.Errorf("expected POST method, got %s", req.Method) 36 } 37 return &http.Response{ 38 StatusCode: http.StatusOK, 39 Body: io.NopCloser(bytes.NewReader([]byte(""))), 40 }, nil 41 }), 42 } 43 44 err := client.PluginSet(context.Background(), "plugin_name", []string{"arg1"}) 45 if err != nil { 46 t.Fatal(err) 47 } 48 }