github.com/rhatdan/docker@v0.7.7-0.20180119204836-47a0dcbcd20a/client/plugin_enable_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 "github.com/docker/docker/api/types" 12 "golang.org/x/net/context" 13 ) 14 15 func TestPluginEnableError(t *testing.T) { 16 client := &Client{ 17 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 18 } 19 20 err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) 21 if err == nil || err.Error() != "Error response from daemon: Server error" { 22 t.Fatalf("expected a Server Error, got %v", err) 23 } 24 } 25 26 func TestPluginEnable(t *testing.T) { 27 expectedURL := "/plugins/plugin_name/enable" 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 != "POST" { 35 return nil, fmt.Errorf("expected POST method, got %s", req.Method) 36 } 37 return &http.Response{ 38 StatusCode: http.StatusOK, 39 Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), 40 }, nil 41 }), 42 } 43 44 err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) 45 if err != nil { 46 t.Fatal(err) 47 } 48 }