github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/config_remove_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/stretchr/testify/assert" 12 "golang.org/x/net/context" 13 ) 14 15 func TestConfigRemoveUnsupported(t *testing.T) { 16 client := &Client{ 17 version: "1.29", 18 client: &http.Client{}, 19 } 20 err := client.ConfigRemove(context.Background(), "config_id") 21 assert.EqualError(t, err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`) 22 } 23 24 func TestConfigRemoveError(t *testing.T) { 25 client := &Client{ 26 version: "1.30", 27 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 28 } 29 30 err := client.ConfigRemove(context.Background(), "config_id") 31 if err == nil || err.Error() != "Error response from daemon: Server error" { 32 t.Fatalf("expected a Server Error, got %v", err) 33 } 34 } 35 36 func TestConfigRemove(t *testing.T) { 37 expectedURL := "/v1.30/configs/config_id" 38 39 client := &Client{ 40 version: "1.30", 41 client: newMockClient(func(req *http.Request) (*http.Response, error) { 42 if !strings.HasPrefix(req.URL.Path, expectedURL) { 43 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 44 } 45 if req.Method != "DELETE" { 46 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 47 } 48 return &http.Response{ 49 StatusCode: http.StatusOK, 50 Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), 51 }, nil 52 }), 53 } 54 55 err := client.ConfigRemove(context.Background(), "config_id") 56 if err != nil { 57 t.Fatal(err) 58 } 59 }