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