@@ -91,3 +91,47 @@ func TestClientAPIPrefix(t *testing.T) {
9191 }
9292 }
9393}
94+
95+ func TestClientHeader (t * testing.T ) {
96+ type testcase struct {
97+ host string
98+ header string
99+ value string
100+ path []string
101+ }
102+
103+ tcs := []testcase {
104+ {header : "Authorization" , value : "Bearer sdneijfnejvzfregfwe" , path : []string {"version" }},
105+ {header : "Content-Type" , value : "text/plain" , path : []string {"version" }},
106+ }
107+
108+ for _ , tc := range tcs {
109+ var called bool
110+
111+ s := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
112+ called = true
113+ t .Log (r )
114+
115+ if token := r .Header .Get (tc .header ); token != tc .value {
116+ t .Errorf ("expected authorization %q, got %q" , tc .value , token )
117+ }
118+
119+ expPath := "/" + strings .Join (tc .path , "/" )
120+ if path := r .URL .Path ; path != expPath {
121+ t .Errorf ("expected path %q, got %q" , expPath , path )
122+ }
123+
124+ w .WriteHeader (http .StatusOK )
125+ }))
126+ testClient := s .Client ()
127+ tc .host = s .URL
128+ r := & cmds.Request {Path : tc .path , Command : & cmds.Command {}, Root : & cmds.Command {}}
129+ c := NewClient (tc .host , ClientWithHeader (tc .header , tc .value )).(* client )
130+ c .httpClient = testClient
131+ c .send (r )
132+
133+ if ! called {
134+ t .Error ("handler has not been called" )
135+ }
136+ }
137+ }
0 commit comments