github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/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/ioutil" 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/assert" 15 is "gotest.tools/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 err == nil || err.Error() != "Error response from daemon: Server error" { 35 t.Fatalf("expected a Server Error, got %v", err) 36 } 37 if !errdefs.IsSystem(err) { 38 t.Fatalf("expected a Server Error, got %T", err) 39 } 40 } 41 42 func TestConfigUpdate(t *testing.T) { 43 expectedURL := "/v1.30/configs/config_id/update" 44 45 client := &Client{ 46 version: "1.30", 47 client: newMockClient(func(req *http.Request) (*http.Response, error) { 48 if !strings.HasPrefix(req.URL.Path, expectedURL) { 49 return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) 50 } 51 if req.Method != "POST" { 52 return nil, fmt.Errorf("expected POST method, got %s", req.Method) 53 } 54 return &http.Response{ 55 StatusCode: http.StatusOK, 56 Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), 57 }, nil 58 }), 59 } 60 61 err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{}) 62 if err != nil { 63 t.Fatal(err) 64 } 65 }