Skip to content
This repository has been archived by the owner on Nov 23, 2019. It is now read-only.

Commit

Permalink
Merge pull request #185 from nishanttotla/version-update-function
Browse files Browse the repository at this point in the history
Adding function to allow for updating client version
  • Loading branch information
vdemeester committed Apr 4, 2016
2 parents 8924d69 + c3e3572 commit 37cc88a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func (cli *Client) ClientVersion() string {
return cli.version
}

// UpdateClientVersion updates the version string associated with this
// instance of the Client.
func (cli *Client) UpdateClientVersion(v string) {
cli.version = v
}

// ParseHost verifies that the given host strings is valid.
func ParseHost(host string) (string, string, string, error) {
protoAddrParts := strings.SplitN(host, "://", 2)
Expand Down
47 changes: 47 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package client

import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"strings"
"testing"

"github.com/docker/engine-api/types"
"golang.org/x/net/context"
)

func TestGetAPIPath(t *testing.T) {
Expand Down Expand Up @@ -70,3 +78,42 @@ func TestParseHost(t *testing.T) {
}
}
}

func TestUpdateClientVersion(t *testing.T) {
client := &Client{
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
splitQuery := strings.Split(req.URL.Path, "/")
queryVersion := splitQuery[1]
b, err := json.Marshal(types.Version{
APIVersion: queryVersion,
})
if err != nil {
return nil, err
}
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(b)),
}, nil
}),
}

cases := []struct {
v string
}{
{"1.20"},
{"v1.21"},
{"1.22"},
{"v1.22"},
}

for _, cs := range cases {
client.UpdateClientVersion(cs.v)
r, err := client.ServerVersion(context.Background())
if err != nil {
t.Fatal(err)
}
if strings.TrimPrefix(r.APIVersion, "v") != strings.TrimPrefix(cs.v, "v") {
t.Fatalf("Expected %s, got %s", cs.v, r.APIVersion)
}
}
}

0 comments on commit 37cc88a

Please sign in to comment.