From 888c138f7488f543b19cb3dd44fc70affe3638b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Mon, 18 Mar 2024 16:13:46 -0300 Subject: [PATCH] Set User-Agent based on version of tsuru-client --- tsuru/http/transport.go | 1 + tsuru/http/transport_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tsuru/http/transport.go b/tsuru/http/transport.go index 61cf70cf..2f5b0f45 100644 --- a/tsuru/http/transport.go +++ b/tsuru/http/transport.go @@ -69,6 +69,7 @@ func (v *TerminalRoundTripper) RoundTrip(req *http.Request) (*http.Response, err } verbosity := getVerbosity() req.Header.Add(verbosityHeader, strconv.Itoa(verbosity)) + req.Header.Set("User-Agent", fmt.Sprintf("tsuru-client/%s", v.CurrentVersion)) req.Close = true if verbosity >= TerminalClientOnlyRequest { diff --git a/tsuru/http/transport_test.go b/tsuru/http/transport_test.go index e6d620d6..216dd77d 100644 --- a/tsuru/http/transport_test.go +++ b/tsuru/http/transport_test.go @@ -18,7 +18,8 @@ func (s *S) TestVerboseRoundTripperDumpRequest(c *check.C) { }() out := new(bytes.Buffer) r := TerminalRoundTripper{ - Stdout: out, + Stdout: out, + CurrentVersion: "1.0.0", RoundTripper: &cmdtest.Transport{ Message: "Success!", Status: http.StatusOK, @@ -31,6 +32,7 @@ func (s *S) TestVerboseRoundTripperDumpRequest(c *check.C) { c.Assert(out.String(), check.DeepEquals, "*************************** **********************************\n"+ "GET /users HTTP/1.1\r\n"+ "Host: localhost\r\n"+ + "User-Agent: tsuru-client/1.0.0\r\n"+ "X-Tsuru-Verbosity: 1\r\n"+ "\r\n"+ "*************************** **********************************\n") @@ -44,7 +46,8 @@ func (s *S) TestVerboseRoundTripperDumpRequestResponse2(c *check.C) { out := new(bytes.Buffer) r := TerminalRoundTripper{ - Stdout: out, + Stdout: out, + CurrentVersion: "1.2.0", RoundTripper: &cmdtest.Transport{ Message: "Success!", Status: http.StatusOK, @@ -57,6 +60,7 @@ func (s *S) TestVerboseRoundTripperDumpRequestResponse2(c *check.C) { c.Assert(out.String(), check.DeepEquals, "*************************** **********************************\n"+ "GET /users HTTP/1.1\r\n"+ "Host: localhost\r\n"+ + "User-Agent: tsuru-client/1.2.0\r\n"+ "X-Tsuru-Verbosity: 2\r\n"+ "\r\n"+ "*************************** **********************************\n"+