77 "errors"
88 "flag"
99 "io"
10- "io/ioutil"
1110 "net/http"
11+ "os"
1212 "os/exec"
1313 "strconv"
1414 "testing"
@@ -20,7 +20,7 @@ import (
2020 "google.golang.org/grpc/credentials/insecure"
2121 "google.golang.org/grpc/status"
2222
23- google_protobuf "github.com/golang/protobuf/ptypes/empty"
23+ protobuf "github.com/golang/protobuf/ptypes/empty"
2424 "github.com/gorilla/mux"
2525 "github.com/prometheus/client_golang/prometheus"
2626 "github.com/stretchr/testify/require"
@@ -32,27 +32,27 @@ import (
3232
3333type FakeServer struct {}
3434
35- func (f FakeServer ) FailWithError (ctx context.Context , req * google_protobuf .Empty ) (* google_protobuf .Empty , error ) {
35+ func (f FakeServer ) FailWithError (_ context.Context , _ * protobuf .Empty ) (* protobuf .Empty , error ) {
3636 return nil , errors .New ("test error" )
3737}
3838
39- func (f FakeServer ) FailWithHTTPError (ctx context.Context , req * FailWithHTTPErrorRequest ) (* google_protobuf .Empty , error ) {
39+ func (f FakeServer ) FailWithHTTPError (_ context.Context , req * FailWithHTTPErrorRequest ) (* protobuf .Empty , error ) {
4040 return nil , httpgrpc .Errorf (int (req .Code ), strconv .Itoa (int (req .Code )))
4141}
4242
43- func (f FakeServer ) Succeed (ctx context.Context , req * google_protobuf .Empty ) (* google_protobuf .Empty , error ) {
44- return & google_protobuf .Empty {}, nil
43+ func (f FakeServer ) Succeed (_ context.Context , _ * protobuf .Empty ) (* protobuf .Empty , error ) {
44+ return & protobuf .Empty {}, nil
4545}
4646
47- func (f FakeServer ) Sleep (ctx context.Context , req * google_protobuf .Empty ) (* google_protobuf .Empty , error ) {
47+ func (f FakeServer ) Sleep (ctx context.Context , _ * protobuf .Empty ) (* protobuf .Empty , error ) {
4848 err := cancelableSleep (ctx , 10 * time .Second )
49- return & google_protobuf .Empty {}, err
49+ return & protobuf .Empty {}, err
5050}
5151
52- func (f FakeServer ) StreamSleep (req * google_protobuf .Empty , stream FakeServer_StreamSleepServer ) error {
52+ func (f FakeServer ) StreamSleep (_ * protobuf .Empty , stream FakeServer_StreamSleepServer ) error {
5353 for x := 0 ; x < 100 ; x ++ {
5454 time .Sleep (time .Second / 100.0 )
55- if err := stream .Send (& google_protobuf .Empty {}); err != nil {
55+ if err := stream .Send (& protobuf .Empty {}); err != nil {
5656 return err
5757 }
5858 }
@@ -133,7 +133,7 @@ func TestDefaultAddresses(t *testing.T) {
133133 require .NoError (t , err )
134134 defer conn .Close ()
135135
136- empty := google_protobuf .Empty {}
136+ empty := protobuf .Empty {}
137137 client := NewFakeServerClient (conn )
138138 _ , err = client .Succeed (context .Background (), & empty )
139139 require .NoError (t , err )
@@ -174,7 +174,7 @@ func TestErrorInstrumentationMiddleware(t *testing.T) {
174174 require .NoError (t , err )
175175 defer conn .Close ()
176176
177- empty := google_protobuf .Empty {}
177+ empty := protobuf .Empty {}
178178 client := NewFakeServerClient (conn )
179179 res , err := client .Succeed (context .Background (), & empty )
180180 require .NoError (t , err )
@@ -247,7 +247,7 @@ func TestErrorInstrumentationMiddleware(t *testing.T) {
247247 require .Error (t , err , context .Canceled )
248248 }
249249
250- conn .Close ()
250+ require . NoError ( t , conn .Close () )
251251 server .Shutdown ()
252252
253253 metrics , err := prometheus .DefaultGatherer .Gather ()
@@ -303,7 +303,7 @@ func TestHTTPInstrumentationMetrics(t *testing.T) {
303303 w .WriteHeader (500 )
304304 })
305305 server .HTTP .HandleFunc ("/sleep10" , func (w http.ResponseWriter , r * http.Request ) {
306- _ , _ = io .Copy (ioutil .Discard , r .Body ) // Consume body, otherwise it's not counted.
306+ _ , _ = io .Copy (io .Discard , r .Body ) // Consume body, otherwise it's not counted.
307307 _ = cancelableSleep (r .Context (), time .Second * 10 )
308308 })
309309
@@ -326,7 +326,7 @@ func TestHTTPInstrumentationMetrics(t *testing.T) {
326326 require .NoError (t , err )
327327 resp , err := http .DefaultClient .Do (req )
328328 require .NoError (t , err )
329- body , err := ioutil .ReadAll (resp .Body )
329+ body , err := io .ReadAll (resp .Body )
330330 require .NoError (t , err )
331331 require .Equal (t , "OK" , string (body ))
332332 }
@@ -482,7 +482,7 @@ func TestRunReturnsError(t *testing.T) {
482482// Test to see what the logging of a 500 error looks like
483483func TestMiddlewareLogging (t * testing.T ) {
484484 var level logging.Level
485- level .Set ("info" )
485+ require . NoError ( t , level .Set ("info" ) )
486486 cfg := Config {
487487 HTTPListenNetwork : DefaultNetwork ,
488488 HTTPListenAddress : "localhost" ,
@@ -513,7 +513,7 @@ func TestMiddlewareLogging(t *testing.T) {
513513
514514func TestTLSServer (t * testing.T ) {
515515 var level logging.Level
516- level .Set ("info" )
516+ require . NoError ( t , level .Set ("info" ) )
517517
518518 cmd := exec .Command ("bash" , "certs/genCerts.sh" , "certs" , "1" )
519519 err := cmd .Run ()
@@ -556,7 +556,7 @@ func TestTLSServer(t *testing.T) {
556556 clientCert , err := tls .LoadX509KeyPair ("certs/client.crt" , "certs/client.key" )
557557 require .NoError (t , err )
558558
559- caCert , err := ioutil .ReadFile (cfg .HTTPTLSConfig .ClientCAs )
559+ caCert , err := os .ReadFile (cfg .HTTPTLSConfig .ClientCAs )
560560 require .NoError (t , err )
561561
562562 caCertPool := x509 .NewCertPool ()
@@ -578,7 +578,7 @@ func TestTLSServer(t *testing.T) {
578578
579579 require .Equal (t , res .StatusCode , http .StatusOK )
580580
581- body , err := ioutil .ReadAll (res .Body )
581+ body , err := io .ReadAll (res .Body )
582582 require .NoError (t , err )
583583 expected := []byte ("Hello World!" )
584584 require .Equal (t , expected , body )
@@ -587,7 +587,7 @@ func TestTLSServer(t *testing.T) {
587587 require .NoError (t , err )
588588 defer conn .Close ()
589589
590- empty := google_protobuf .Empty {}
590+ empty := protobuf .Empty {}
591591 grpcClient := NewFakeServerClient (conn )
592592 grpcRes , err := grpcClient .Succeed (context .Background (), & empty )
593593 require .NoError (t , err )
@@ -598,17 +598,17 @@ type FakeLogger struct {
598598 sourceIPs string
599599}
600600
601- func (f * FakeLogger ) Debugf (format string , args ... interface {}) {}
602- func (f * FakeLogger ) Debugln (args ... interface {}) {}
601+ func (f * FakeLogger ) Debugf (_ string , _ ... interface {}) {}
602+ func (f * FakeLogger ) Debugln (_ ... interface {}) {}
603603
604- func (f * FakeLogger ) Infof (format string , args ... interface {}) {}
605- func (f * FakeLogger ) Infoln (args ... interface {}) {}
604+ func (f * FakeLogger ) Infof (_ string , _ ... interface {}) {}
605+ func (f * FakeLogger ) Infoln (_ ... interface {}) {}
606606
607- func (f * FakeLogger ) Errorf (format string , args ... interface {}) {}
608- func (f * FakeLogger ) Errorln (args ... interface {}) {}
607+ func (f * FakeLogger ) Errorf (_ string , _ ... interface {}) {}
608+ func (f * FakeLogger ) Errorln (_ ... interface {}) {}
609609
610- func (f * FakeLogger ) Warnf (format string , args ... interface {}) {}
611- func (f * FakeLogger ) Warnln (args ... interface {}) {}
610+ func (f * FakeLogger ) Warnf (_ string , _ ... interface {}) {}
611+ func (f * FakeLogger ) Warnln (_ ... interface {}) {}
612612
613613func (f * FakeLogger ) WithField (key string , value interface {}) logging.Interface {
614614 if key == "sourceIPs" {
@@ -618,13 +618,13 @@ func (f *FakeLogger) WithField(key string, value interface{}) logging.Interface
618618 return f
619619}
620620
621- func (f * FakeLogger ) WithFields (fields logging.Fields ) logging.Interface {
621+ func (f * FakeLogger ) WithFields (_ logging.Fields ) logging.Interface {
622622 return f
623623}
624624
625625func TestLogSourceIPs (t * testing.T ) {
626626 var level logging.Level
627- level .Set ("debug" )
627+ require . NoError ( t , level .Set ("debug" ) )
628628 fake := FakeLogger {}
629629 cfg := Config {
630630 HTTPListenNetwork : DefaultNetwork ,
0 commit comments