github.com/rish1988/moby@v25.0.2+incompatible/client/plugin_push_test.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "io" 8 "net/http" 9 "strings" 10 "testing" 11 12 "github.com/docker/docker/api/types/registry" 13 "github.com/docker/docker/errdefs" 14 "gotest.tools/v3/assert" 15 is "gotest.tools/v3/assert/cmp" 16 ) 17 18 func TestPluginPushError(t *testing.T) { 19 client := &Client{ 20 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 21 } 22 23 _, err := client.PluginPush(context.Background(), "plugin_name", "") 24 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 25 } 26 27 func TestPluginPush(t *testing.T) { 28 expectedURL := "/plugins/plugin_name" 29 30 client := &Client{ 31 client: newMockClient(func(req *http.Request) (*http.Response, error) { 32 if !strings.HasPrefix(req.URL.Path, expectedURL) { 33 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 34 } 35 if req.Method != http.MethodPost { 36 return nil, fmt.Errorf("expected POST method, got %s", req.Method) 37 } 38 auth := req.Header.Get(registry.AuthHeader) 39 if auth != "authtoken" { 40 return nil, fmt.Errorf("invalid auth header: expected 'authtoken', got %s", auth) 41 } 42 return &http.Response{ 43 StatusCode: http.StatusOK, 44 Body: io.NopCloser(bytes.NewReader([]byte(""))), 45 }, nil 46 }), 47 } 48 49 _, err := client.PluginPush(context.Background(), "plugin_name", "authtoken") 50 if err != nil { 51 t.Fatal(err) 52 } 53 }