@@ -48,7 +48,7 @@ type tserver struct {
4848 srv * FleetServer
4949}
5050
51- func (s * tserver ) baseUrl () string {
51+ func (s * tserver ) baseURL () string {
5252 input , _ := s .cfg .GetFleetInput ()
5353 tls := input .Server .TLS
5454 schema := "http"
@@ -65,14 +65,14 @@ func (s *tserver) waitExit() error {
6565func startTestServer (ctx context.Context ) (* tserver , error ) {
6666 cfg , err := config .LoadFile ("../../fleet-server.yml" )
6767 if err != nil {
68- return nil , err
68+ return nil , fmt . Errorf ( "config load error: %w" , err )
6969 }
7070
71- logger .Init (cfg , "fleet-server" )
71+ logger .Init (cfg , "fleet-server" ) //nolint:errcheck // test logging setup
7272
7373 port , err := ftesting .FreePort ()
7474 if err != nil {
75- return nil , err
75+ return nil , fmt . Errorf ( "unable to find port: %w" , err )
7676 }
7777
7878 srvcfg := & config.Server {}
@@ -84,7 +84,7 @@ func startTestServer(ctx context.Context) (*tserver, error) {
8484
8585 srv , err := NewFleetServer (cfg , build.Info {Version : serverVersion }, status .NewLog ())
8686 if err != nil {
87- return nil , err
87+ return nil , fmt . Errorf ( "unable to create server: %w" , err )
8888 }
8989
9090 g , ctx := errgroup .WithContext (ctx )
@@ -96,7 +96,7 @@ func startTestServer(ctx context.Context) (*tserver, error) {
9696 tsrv := & tserver {cfg : cfg , g : g , srv : srv }
9797 err = tsrv .waitServerUp (ctx , testWaitServerUp )
9898 if err != nil {
99- return nil , err
99+ return nil , fmt . Errorf ( "unable to start server: %w" , err )
100100 }
101101 return tsrv , nil
102102}
@@ -105,7 +105,7 @@ func (s *tserver) waitServerUp(ctx context.Context, dur time.Duration) error {
105105 start := time .Now ()
106106 cli := cleanhttp .DefaultClient ()
107107 for {
108- res , err := cli .Get (s .baseUrl () + "/api/status" )
108+ res , err := cli .Get (s .baseURL () + "/api/status" ) //nolint:noctx // test setup
109109 if err != nil {
110110 if time .Since (start ) > dur {
111111 return err
@@ -123,7 +123,7 @@ func (s *tserver) waitServerUp(ctx context.Context, dur time.Duration) error {
123123
124124}
125125
126- func (s * tserver ) buildUrl (id string , cmd string ) string {
126+ func (s * tserver ) buildURL (id string , cmd string ) string {
127127 ur := "/api/fleet/agents"
128128 if id != "" {
129129 ur = path .Join (ur , id )
@@ -132,7 +132,7 @@ func (s *tserver) buildUrl(id string, cmd string) string {
132132 ur = path .Join (ur , cmd )
133133 }
134134
135- return s .baseUrl () + ur
135+ return s .baseURL () + ur
136136}
137137
138138func TestServerUnauthorized (t * testing.T ) {
@@ -143,16 +143,16 @@ func TestServerUnauthorized(t *testing.T) {
143143 srv , err := startTestServer (ctx )
144144 require .NoError (t , err )
145145
146- agentId := uuid .Must (uuid .NewV4 ()).String ()
146+ agentID := uuid .Must (uuid .NewV4 ()).String ()
147147 cli := cleanhttp .DefaultClient ()
148148
149149 agenturls := []string {
150- srv .buildUrl ( agentId , "checkin" ),
151- srv .buildUrl ( agentId , "acks" ),
150+ srv .buildURL ( agentID , "checkin" ),
151+ srv .buildURL ( agentID , "acks" ),
152152 }
153153
154154 allurls := []string {
155- srv .buildUrl ("" , "enroll" ),
155+ srv .buildURL ("" , "enroll" ),
156156 }
157157 allurls = append (allurls , agenturls ... )
158158
@@ -161,7 +161,7 @@ func TestServerUnauthorized(t *testing.T) {
161161 // TODO: revisit error response format
162162 t .Run ("no auth header" , func (t * testing.T ) {
163163 for _ , u := range allurls {
164- res , err := cli .Post (u , "application/json" , bytes .NewBuffer ([]byte ("{}" )))
164+ res , err := cli .Post (u , "application/json" , bytes .NewBuffer ([]byte ("{}" ))) //nolint:noctx // test case
165165 if err != nil {
166166 t .Fatal (err )
167167 }
@@ -190,9 +190,8 @@ func TestServerUnauthorized(t *testing.T) {
190190
191191 // Unauthorized, expecting error from /_security/_authenticate
192192 t .Run ("unauthorized" , func (t * testing.T ) {
193-
194193 for _ , u := range agenturls {
195- req , err := http .NewRequest ("POST" , u , bytes .NewBuffer ([]byte ("{}" )))
194+ req , err := http .NewRequest ("POST" , u , bytes .NewBuffer ([]byte ("{}" ))) //nolint:noctx // test case
196195 require .NoError (t , err )
197196 req .Header .Set ("Content-Type" , "application/json" )
198197 req .Header .Set ("Authorization" , "ApiKey ZExqY1hYWUJJUVVxWDVia2JvVGM6M05XaUt5aHBRYk9YSTRQWDg4YWp0UQ==" )
@@ -225,7 +224,7 @@ func TestServerUnauthorized(t *testing.T) {
225224
226225 // Stop test server
227226 cancel ()
228- srv .waitExit ()
227+ srv .waitExit () //nolint:errcheck // test case
229228}
230229
231230func TestServerInstrumentation (t * testing.T ) {
@@ -239,7 +238,7 @@ func TestServerInstrumentation(t *testing.T) {
239238 return
240239 }
241240 tracerConnected <- struct {}{}
242- io .Copy (io .Discard , req .Body )
241+ io .Copy (io .Discard , req .Body ) //nolint:errcheck // test case
243242 tracerDisconnected <- struct {}{}
244243 }))
245244 defer server .Close ()
@@ -248,8 +247,7 @@ func TestServerInstrumentation(t *testing.T) {
248247 srv , err := startTestServer (ctx )
249248 require .NoError (t , err )
250249
251- newInstrumentationCfg := func (cfg config.Config , instr config.Instrumentation ) {
252- cfg .Inputs [0 ] = cfg .Inputs [0 ]
250+ newInstrumentationCfg := func (cfg config.Config , instr config.Instrumentation ) { //nolint:govet // mutex should not be copied in operation (hopefully)
253251 cfg .Inputs [0 ].Server .Instrumentation = instr
254252
255253 newCfg , err := srv .cfg .Merge (& cfg )
@@ -259,18 +257,23 @@ func TestServerInstrumentation(t *testing.T) {
259257 }
260258
261259 // Enable instrumentation
262- newInstrumentationCfg (* srv .cfg , config.Instrumentation {
260+ newInstrumentationCfg (* srv .cfg , config.Instrumentation { //nolint:govet // mutex should not be copied in operation (hopefully)
263261 Enabled : true ,
264262 Hosts : []string {server .URL },
265263 })
266264
267265 stopClient := make (chan struct {})
268266 cli := cleanhttp .DefaultClient ()
269267 callCheckinFunc := func () {
268+ var Err error
269+ defer require .NoError (t , Err )
270270 for {
271- agentId := "1e4954ce-af37-4731-9f4a-407b08e69e42"
272- cli .Post (srv .buildUrl (agentId , "checkin" ), "application/json" , bytes .NewBuffer ([]byte ("{}" )))
273- require .NoError (t , err )
271+ agentID := "1e4954ce-af37-4731-9f4a-407b08e69e42"
272+ res , err := cli .Post (srv .buildURL (agentID , "checkin" ), "application/json" , bytes .NewBuffer ([]byte ("{}" ))) //nolint:noctx,staticcheck // test case
273+ if res != nil && res .Body != nil {
274+ res .Body .Close ()
275+ }
276+ Err = err //nolint:ineffassign,staticcheck,wastedassign // ugly work around for error checking
274277 select {
275278 case <- ctx .Done ():
276279 return
@@ -292,7 +295,7 @@ func TestServerInstrumentation(t *testing.T) {
292295 }
293296
294297 // Turn instrumentation off
295- newInstrumentationCfg (* srv .cfg , config.Instrumentation {
298+ newInstrumentationCfg (* srv .cfg , config.Instrumentation { //nolint:govet // mutex should not be copied in operation (hopefully)
296299 Enabled : false ,
297300 Hosts : []string {server .URL },
298301 })
0 commit comments