github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+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/ioutil"
     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  	if !errdefs.IsSystem(err) {
    34  		t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err)
    35  	}
    36  }
    37  
    38  func TestConfigRemove(t *testing.T) {
    39  	expectedURL := "/v1.30/configs/config_id"
    40  
    41  	client := &Client{
    42  		version: "1.30",
    43  		client: newMockClient(func(req *http.Request) (*http.Response, error) {
    44  			if !strings.HasPrefix(req.URL.Path, expectedURL) {
    45  				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
    46  			}
    47  			if req.Method != http.MethodDelete {
    48  				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
    49  			}
    50  			return &http.Response{
    51  				StatusCode: http.StatusOK,
    52  				Body:       ioutil.NopCloser(bytes.NewReader([]byte("body"))),
    53  			}, nil
    54  		}),
    55  	}
    56  
    57  	err := client.ConfigRemove(context.Background(), "config_id")
    58  	if err != nil {
    59  		t.Fatal(err)
    60  	}
    61  }