Skip to content

Commit 5745c39

Browse files
feat(version): add platform version to client object (#47)
1 parent 658d0ab commit 5745c39

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

deis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type Client struct {
7777
// API Version used by the controller, set after a http request.
7878
ControllerAPIVersion string
7979

80+
// Version of the deis platform in use, set after a http request.
81+
DeisVersion string
82+
8083
// Token is used to authenticate the request against the API.
8184
Token string
8285
}

http.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ func (c *Client) Request(method string, path string, body []byte) (*http.Respons
6161

6262
apiVersion := res.Header.Get("DEIS_API_VERSION")
6363

64-
// Update controller api version
64+
// Update controller api and platform version
6565
c.ControllerAPIVersion = apiVersion
66+
c.DeisVersion = res.Header.Get("DEIS_PLATFORM_VERSION")
6667

6768
// Return results along with api compatibility error
6869
return res, checkAPICompatibility(apiVersion)

http_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
)
1010

1111
type fakeHTTPServer struct {
12-
Version string
12+
Version string
13+
PlatformVersion string
1314
}
1415

1516
const limitedFixture string = `
@@ -30,6 +31,7 @@ const limitedFixture string = `
3031

3132
func (f fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
3233
res.Header().Add("DEIS_API_VERSION", f.Version)
34+
res.Header().Add("DEIS_PLATFORM_VERSION", f.PlatformVersion)
3335

3436
eA := "test"
3537

@@ -136,7 +138,7 @@ func TestAPIMistmatch(t *testing.T) {
136138
func TestBasicRequest(t *testing.T) {
137139
t.Parallel()
138140

139-
handler := fakeHTTPServer{Version: APIVersion}
141+
handler := fakeHTTPServer{Version: APIVersion, PlatformVersion: "v9000"}
140142
server := httptest.NewServer(handler)
141143
defer server.Close()
142144

@@ -162,6 +164,10 @@ func TestBasicRequest(t *testing.T) {
162164
t.Errorf("Expected %s, Got %s", handler.Version, deis.ControllerAPIVersion)
163165
}
164166

167+
if deis.DeisVersion != handler.PlatformVersion {
168+
t.Errorf("Expected %s, Got %s", handler.PlatformVersion, deis.DeisVersion)
169+
}
170+
165171
// Make sure the request doesn't modify the URL
166172
if deis.ControllerURL.String() != server.URL {
167173
t.Errorf("Expected %s, Got %s", server.URL, deis.ControllerURL.String())

0 commit comments

Comments
 (0)