diff --git a/http/request_parser_test.go b/http/request_parser_test.go index 5a5b1e0d..ad5dadfb 100644 --- a/http/request_parser_test.go +++ b/http/request_parser_test.go @@ -14,13 +14,13 @@ func Test_NilRequest(t *testing.T) { } func Test_EmptyRequests(t *testing.T) { - b := []byte(fmt.Sprintf(`[]`)) + b := []byte(`[]`) _, err := ParseRequest(b) if err != ErrNoStatements { t.Fatalf("empty simple request did not result in correct error") } - b = []byte(fmt.Sprintf(`[[]]`)) + b = []byte(`[[]]`) _, err = ParseRequest(b) if err != ErrNoStatements { t.Fatalf("empty parameterized request did not result in correct error") @@ -258,17 +258,17 @@ func Test_MixedInvalidRequest(t *testing.T) { } func Test_SingleInvalidTypeRequests(t *testing.T) { - _, err := ParseRequest([]byte(fmt.Sprintf(`[1]`))) + _, err := ParseRequest([]byte(`[1]`)) if err != ErrInvalidJSON { t.Fatal("got unexpected error for invalid request") } - _, err = ParseRequest([]byte(fmt.Sprintf(`[[1]]`))) + _, err = ParseRequest([]byte(`[[1]]`)) if err != ErrInvalidRequest { t.Fatal("got unexpected error for invalid request") } - _, err = ParseRequest([]byte(fmt.Sprintf(`[[1, "x", 2]]`))) + _, err = ParseRequest([]byte(`[[1, "x", 2]]`)) if err != ErrInvalidRequest { t.Fatal("got unexpected error for invalid request") } diff --git a/http/service.go b/http/service.go index e20d7f23..7424c828 100644 --- a/http/service.go +++ b/http/service.go @@ -10,7 +10,6 @@ import ( "expvar" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -381,7 +380,6 @@ func (s *Service) Close() { <-s.queueDone s.ln.Close() - return } // HTTPS returns whether this service is using HTTPS. @@ -458,7 +456,7 @@ func (s *Service) handleJoin(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -537,7 +535,7 @@ func (s *Service) handleNotify(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -597,7 +595,7 @@ func (s *Service) handleRemove(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return @@ -806,7 +804,7 @@ func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return @@ -1227,7 +1225,7 @@ func (s *Service) queuedExecute(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return @@ -1260,7 +1258,7 @@ func (s *Service) queuedExecute(w http.ResponseWriter, r *http.Request) { var fc queue.FlushChannel if wait { stats.Add(numQueuedExecutionsWait, 1) - fc = make(queue.FlushChannel, 0) + fc = make(queue.FlushChannel) } seqNum, err := s.stmtQueue.Write(stmts, fc) @@ -1283,7 +1281,6 @@ func (s *Service) queuedExecute(w http.ResponseWriter, r *http.Request) { resp.end = time.Now() s.writeResponse(w, r, resp) - return } // execute handles queries that modify the database. @@ -1296,7 +1293,7 @@ func (s *Service) execute(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return @@ -1757,7 +1754,7 @@ func requestQueries(r *http.Request) ([]*command.Statement, error) { }, nil } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { return nil, errors.New("bad query POST request") } @@ -1959,24 +1956,6 @@ func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteReq } } -// queryRequestFromStrings converts a slice of strings into a command.QueryRequest -func queryRequestFromStrings(s []string, timings, tx bool) *command.QueryRequest { - stmts := make([]*command.Statement, len(s)) - for i := range s { - stmts[i] = &command.Statement{ - Sql: s[i], - } - - } - return &command.QueryRequest{ - Request: &command.Request{ - Statements: stmts, - Transaction: tx, - }, - Timings: timings, - } -} - // validateSQLiteFile checks that the supplied data looks like a SQLite database // file. See https://www.sqlite.org/fileformat.html func validSQLiteFile(b []byte) bool { diff --git a/http/service_test.go b/http/service_test.go index 50d344a4..3d7e254f 100644 --- a/http/service_test.go +++ b/http/service_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -233,6 +232,9 @@ func Test_404Routes_ExpvarPprofDisabled(t *testing.T) { "/debug/pprof/symbol", } { req, err := http.NewRequest("GET", host+path, nil) + if err != nil { + t.Fatalf("failed to create request: %s", err.Error()) + } resp, err := client.Do(req) if err != nil { t.Fatalf("failed to make request: %s", err.Error()) @@ -648,7 +650,10 @@ func Test_BackupFlagsNoLeaderRemoteFetch(t *testing.T) { t.Fatalf("failed to get expected StatusOK for remote backup fetch, got %d", resp.StatusCode) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + t.Fatalf("failed to read response body: %s", err.Error()) + } if exp, got := backupData, string(body); exp != got { t.Fatalf("received incorrect backup data, exp: %s, got: %s", exp, got) } @@ -740,7 +745,7 @@ func Test_LoadFlagsNoLeader(t *testing.T) { clusterLoadCalled := false c.loadFn = func(lr *command.LoadRequest, nodeAddr string, timeout time.Duration) error { clusterLoadCalled = true - if bytes.Compare(lr.Data, testData) != 0 { + if !bytes.Equal(lr.Data, testData) { t.Fatalf("wrong data passed to cluster load") } return nil @@ -1337,12 +1342,3 @@ func mustParseDuration(d string) time.Duration { return dur } } - -func mustReadResponseBody(resp *http.Response) string { - response, err := ioutil.ReadAll(resp.Body) - if err != nil { - panic("failed to ReadAll response body") - } - resp.Body.Close() - return string(response) -}