Commit 927c084f authored by Adam Reese's avatar Adam Reese

feat(client): add helm user agent

parent 1e741afb
...@@ -100,6 +100,9 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read ...@@ -100,6 +100,9 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read
// callHTTP is a low-level primative for executing HTTP operations. // callHTTP is a low-level primative for executing HTTP operations.
func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) { func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) {
request, err := http.NewRequest(method, path, reader) request, err := http.NewRequest(method, path, reader)
// TODO: dynamically set version
request.Header.Set("User-Agent", "helm/0.0.1")
request.Header.Add("Content-Type", "application/json") request.Header.Add("Content-Type", "application/json")
client := http.Client{ client := http.Client{
......
...@@ -3,6 +3,7 @@ package dm ...@@ -3,6 +3,7 @@ package dm
import ( import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings"
"testing" "testing"
"github.com/kubernetes/deployment-manager/common" "github.com/kubernetes/deployment-manager/common"
...@@ -65,15 +66,11 @@ func TestURL(t *testing.T) { ...@@ -65,15 +66,11 @@ func TestURL(t *testing.T) {
type fakeClient struct { type fakeClient struct {
*Client *Client
server *httptest.Server server *httptest.Server
handler http.HandlerFunc handler http.HandlerFunc
response []byte
} }
func (c *fakeClient) setup() *fakeClient { func (c *fakeClient) setup() *fakeClient {
c.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(c.response)
})
c.server = httptest.NewServer(c.handler) c.server = httptest.NewServer(c.handler)
c.Client = NewClient(c.server.URL) c.Client = NewClient(c.server.URL)
return c return c
...@@ -83,9 +80,22 @@ func (c *fakeClient) teardown() { ...@@ -83,9 +80,22 @@ func (c *fakeClient) teardown() {
c.server.Close() c.server.Close()
} }
func TestUserAgent(t *testing.T) {
fc := &fakeClient{
handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.UserAgent(), "helm") {
t.Error("user agent is not set")
}
}),
}
fc.setup().ListDeployments()
}
func TestListDeployments(t *testing.T) { func TestListDeployments(t *testing.T) {
fc := &fakeClient{ fc := &fakeClient{
response: []byte(`["guestbook.yaml"]`), handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`["guestbook.yaml"]`))
}),
} }
defer fc.teardown() defer fc.teardown()
...@@ -101,7 +111,9 @@ func TestListDeployments(t *testing.T) { ...@@ -101,7 +111,9 @@ func TestListDeployments(t *testing.T) {
func TestGetDeployment(t *testing.T) { func TestGetDeployment(t *testing.T) {
fc := &fakeClient{ fc := &fakeClient{
response: []byte(`{"name":"guestbook.yaml","id":0,"createdAt":"2016-02-08T12:17:49.251658308-08:00","deployedAt":"2016-02-08T12:17:49.251658589-08:00","modifiedAt":"2016-02-08T12:17:51.177518098-08:00","deletedAt":"0001-01-01T00:00:00Z","state":{"status":"Deployed"},"latestManifest":"manifest-1454962670728402229"}`), handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"name":"guestbook.yaml","id":0,"createdAt":"2016-02-08T12:17:49.251658308-08:00","deployedAt":"2016-02-08T12:17:49.251658589-08:00","modifiedAt":"2016-02-08T12:17:51.177518098-08:00","deletedAt":"0001-01-01T00:00:00Z","state":{"status":"Deployed"},"latestManifest":"manifest-1454962670728402229"}`))
}),
} }
defer fc.teardown() defer fc.teardown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment