github.com/rumpl/bof@v23.0.0-rc.2+incompatible/client/config_update_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/swarm"
    13  	"github.com/docker/docker/errdefs"
    14  	"gotest.tools/v3/assert"
    15  	is "gotest.tools/v3/assert/cmp"
    16  )
    17  
    18  func TestConfigUpdateUnsupported(t *testing.T) {
    19  	client := &Client{
    20  		version: "1.29",
    21  		client:  &http.Client{},
    22  	}
    23  	err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{})
    24  	assert.Check(t, is.Error(err, `"config update" requires API version 1.30, but the Docker daemon API version is 1.29`))
    25  }
    26  
    27  func TestConfigUpdateError(t *testing.T) {
    28  	client := &Client{
    29  		version: "1.30",
    30  		client:  newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
    31  	}
    32  
    33  	err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{})
    34  	if !errdefs.IsSystem(err) {
    35  		t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err)
    36  	}
    37  }
    38  
    39  func TestConfigUpdate(t *testing.T) {
    40  	expectedURL := "/v1.30/configs/config_id/update"
    41  
    42  	client := &Client{
    43  		version: "1.30",
    44  		client: newMockClient(func(req *http.Request) (*http.Response, error) {
    45  			if !strings.HasPrefix(req.URL.Path, expectedURL) {
    46  				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
    47  			}
    48  			if req.Method != http.MethodPost {
    49  				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
    50  			}
    51  			return &http.Response{
    52  				StatusCode: http.StatusOK,
    53  				Body:       io.NopCloser(bytes.NewReader([]byte("body"))),
    54  			}, nil
    55  		}),
    56  	}
    57  
    58  	err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{})
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  }