github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/secret_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 TestSecretUpdateUnsupported(t *testing.T) { 17 client := &Client{ 18 version: "1.24", 19 client: &http.Client{}, 20 } 21 err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) 22 assert.EqualError(t, err, `"secret update" requires API version 1.25, but the Docker daemon API version is 1.24`) 23 } 24 25 func TestSecretUpdateError(t *testing.T) { 26 client := &Client{ 27 version: "1.25", 28 client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), 29 } 30 31 err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) 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 TestSecretUpdate(t *testing.T) { 38 expectedURL := "/v1.25/secrets/secret_id/update" 39 40 client := &Client{ 41 version: "1.25", 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.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) 57 if err != nil { 58 t.Fatal(err) 59 } 60 }