github.com/rish1988/moby@v25.0.2+incompatible/client/config_remove_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/errdefs" 13 "gotest.tools/v3/assert" 14 is "gotest.tools/v3/assert/cmp" 15 ) 16 17 func TestConfigRemoveUnsupported(t *testing.T) { 18 client := &Client{ 19 version: "1.29", 20 client: &http.Client{}, 21 } 22 err := client.ConfigRemove(context.Background(), "config_id") 23 assert.Check(t, is.Error(err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`)) 24 } 25 26 func TestConfigRemoveError(t *testing.T) { 27 client := &Client{ 28 version: "1.30", 29 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 30 } 31 32 err := client.ConfigRemove(context.Background(), "config_id") 33 assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) 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 != http.MethodDelete { 46 return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) 47 } 48 return &http.Response{ 49 StatusCode: http.StatusOK, 50 Body: io.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 }