diff --git a/cluster/join.go b/cluster/join.go index 1cff1202..0bd39f15 100644 --- a/cluster/join.go +++ b/cluster/join.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "log" "net" "net/http" @@ -148,7 +148,7 @@ func (j *Joiner) join(joinAddr, id, addr string, voter bool) (string, error) { } defer resp.Body.Close() - b, err = ioutil.ReadAll(resp.Body) + b, err = io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/cluster/join_test.go b/cluster/join_test.go index 87b7570e..3fe4f92a 100644 --- a/cluster/join_test.go +++ b/cluster/join_test.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -28,7 +28,7 @@ func Test_SingleJoinOK(t *testing.T) { t.Fatalf("incorrect Content-Type set") } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -74,7 +74,7 @@ func Test_SingleJoinHTTPSOK(t *testing.T) { t.Fatalf("incorrect Content-Type set") } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -130,7 +130,7 @@ func Test_SingleJoinOKBasicAuth(t *testing.T) { t.Fatalf("bad Basic Auth credentials received (%s, %s", username, password) } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return diff --git a/cluster/service.go b/cluster/service.go index f4c3a8f1..a8d29ed4 100644 --- a/cluster/service.go +++ b/cluster/service.go @@ -263,9 +263,7 @@ func (s *Service) handleConn(conn net.Conn) { resp.Error = err.Error() } else { resp.Results = make([]*command.ExecuteResult, len(res)) - for i := range res { - resp.Results[i] = res[i] - } + copy(resp.Results, res) } } @@ -291,9 +289,7 @@ func (s *Service) handleConn(conn net.Conn) { resp.Error = err.Error() } else { resp.Rows = make([]*command.QueryRows, len(res)) - for i := range res { - resp.Rows[i] = res[i] - } + copy(resp.Rows, res) } } diff --git a/cluster/service_db_clstr_test.go b/cluster/service_db_clstr_test.go index 0094ff8c..d349dcac 100644 --- a/cluster/service_db_clstr_test.go +++ b/cluster/service_db_clstr_test.go @@ -296,7 +296,7 @@ func Test_ServiceBackup(t *testing.T) { t.Fatalf("failed to backup database: %s", err.Error()) } - if bytes.Compare(buf.Bytes(), testData) != 0 { + if !bytes.Equal(buf.Bytes(), testData) { t.Fatalf("backup data is not as expected, exp: %s, got: %s", testData, buf.Bytes()) } @@ -332,7 +332,7 @@ func Test_ServiceLoad(t *testing.T) { testData := []byte("this is SQLite data") db.loadFn = func(lr *command.LoadRequest) error { called = true - if bytes.Compare(lr.Data, testData) != 0 { + if !bytes.Equal(lr.Data, testData) { t.Fatalf("load data is not as expected, exp: %s, got: %s", testData, lr.Data) } return nil @@ -458,13 +458,6 @@ func queryRequestFromStrings(s []string) *command.QueryRequest { } } -func backupRequestSQL(leader bool) *command.BackupRequest { - return &command.BackupRequest{ - Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL, - Leader: leader, - } -} - func backupRequestBinary(leader bool) *command.BackupRequest { return &command.BackupRequest{ Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY, diff --git a/rtls/config.go b/rtls/config.go index e81859e4..6b380e02 100644 --- a/rtls/config.go +++ b/rtls/config.go @@ -29,7 +29,7 @@ func CreateConfig(certFile, keyFile, caCertFile string, noverify, tls1011 bool) // load the CA certificate file, if provided, as the root CA and client CA if caCertFile != "" { - asn1Data, err := ioutil.ReadFile(caCertFile) + asn1Data, err := os.ReadFile(caCertFile) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func CreateClientConfig(certFile, keyFile, caCertFile string, noverify, tls1011 } } if caCertFile != "" { - asn1Data, err := ioutil.ReadFile(caCertFile) + asn1Data, err := os.ReadFile(caCertFile) if err != nil { return nil, err } @@ -99,7 +99,7 @@ func CreateServerConfig(certFile, keyFile, caCertFile string, noverify, tls1011 return nil, err } if caCertFile != "" { - asn1Data, err := ioutil.ReadFile(caCertFile) + asn1Data, err := os.ReadFile(caCertFile) if err != nil { return nil, err } diff --git a/tcp/dialer_test.go b/tcp/dialer_test.go index a53ba7d8..bea9325a 100644 --- a/tcp/dialer_test.go +++ b/tcp/dialer_test.go @@ -121,7 +121,7 @@ func (e *echoServer) Start(t *testing.T) { // Successful testing can cause this. return } - t.Fatalf("failed to accept a connection: %s", err.Error()) + t.Logf("failed to accept a connection: %s", err.Error()) } go func(c net.Conn) { buf := make([]byte, 1) diff --git a/tcp/mux_test.go b/tcp/mux_test.go index 7b9d5e05..7c12086e 100644 --- a/tcp/mux_test.go +++ b/tcp/mux_test.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/tls" "io" - "io/ioutil" "log" "net" "os" @@ -41,7 +40,7 @@ func TestMux(t *testing.T) { } mux.Timeout = 200 * time.Millisecond if !testing.Verbose() { - mux.Logger = log.New(ioutil.Discard, "", 0) + mux.Logger = log.New(io.Discard, "", 0) } for i := uint8(0); i < n; i++ { ln := mux.Listen(i) @@ -140,7 +139,7 @@ func TestMux_Advertise(t *testing.T) { } mux.Timeout = 200 * time.Millisecond if !testing.Verbose() { - mux.Logger = log.New(ioutil.Discard, "", 0) + mux.Logger = log.New(io.Discard, "", 0) } layer := mux.Listen(1)