From d4e637eb9b39ccb5801fd8bc8fabe0592f405e09 Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 23 Sep 2022 14:18:31 -0500 Subject: [PATCH] drop ioutil The ioutil package is deprecated, with all of its functions having moved into os or io. Do the replacements so we stop having this impending. --- client/logimport_test.go | 1 - ctl/cli.go | 3 +- ctl/restore_tar.go | 7 +-- executor_test.go | 3 +- server/handler_test.go | 128 +++++++++++++++++++-------------------- 5 files changed, 69 insertions(+), 73 deletions(-) diff --git a/client/logimport_test.go b/client/logimport_test.go index bea2b1e72..51d736c50 100644 --- a/client/logimport_test.go +++ b/client/logimport_test.go @@ -92,7 +92,6 @@ func TestEncodeDecode(t *testing.T) { }) } - buf, err := os.CreateTemp("", "") if err != nil { t.Fatalf("getting temp file: %v", err) diff --git a/ctl/cli.go b/ctl/cli.go index c5b2713c5..b11713d96 100644 --- a/ctl/cli.go +++ b/ctl/cli.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -188,7 +187,7 @@ func (cmd *CLICommand) executeCommands(ctx context.Context) error { } var sqlResponse response - fullbod, err := ioutil.ReadAll(resp.Body) + fullbod, err := io.ReadAll(resp.Body) if err != nil { return errors.Wrap(err, "reading response") } diff --git a/ctl/restore_tar.go b/ctl/restore_tar.go index 618b77994..e9ca669ae 100644 --- a/ctl/restore_tar.go +++ b/ctl/restore_tar.go @@ -9,7 +9,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" gohttp "net/http" "os" "strconv" @@ -171,7 +170,7 @@ func (cmd *RestoreTarCommand) Run(ctx context.Context) (err error) { return fmt.Errorf("no fragmentNodes available") } - shardBytes, err := ioutil.ReadAll(tarReader) // this feels wrong but works for now + shardBytes, err := io.ReadAll(tarReader) // this feels wrong but works for now if err != nil { return err } @@ -200,7 +199,7 @@ func (cmd *RestoreTarCommand) Run(ctx context.Context) (err error) { if err != nil { return err } - shardBytes, err := ioutil.ReadAll(tarReader) // this feels wrong but works for now + shardBytes, err := io.ReadAll(tarReader) // this feels wrong but works for now if err != nil { return err } @@ -228,7 +227,7 @@ func (cmd *RestoreTarCommand) Run(ctx context.Context) (err error) { case "translate": logger.Printf("field keys %v %v", indexName, fieldName) //needs to go to all nodes - shardBytes, err := ioutil.ReadAll(tarReader) // this feels wrong but works for now + shardBytes, err := io.ReadAll(tarReader) // this feels wrong but works for now if err != nil { return err } diff --git a/executor_test.go b/executor_test.go index fb18ce87e..699e542cd 100644 --- a/executor_test.go +++ b/executor_test.go @@ -11,7 +11,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "math" "math/rand" _ "net/http/pprof" @@ -6887,7 +6886,7 @@ func TestExecutor_Execute_NoIndex(t *testing.T) { func TestExecutor_Execute_CountDistinct(t *testing.T) { // This schema has indexes named e, p, and s. We can then // use c.Idx(e) or Sprintf(%e, idx) to match these names up. - data, err := ioutil.ReadFile("testdata/schema.json") + data, err := os.ReadFile("testdata/schema.json") if err != nil { t.Fatal(err) } diff --git a/server/handler_test.go b/server/handler_test.go index fa77b0146..6ebc6ade3 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -10,7 +10,7 @@ import ( "fmt" "io" "math" - gohttp "net/http" + "net/http" "net/http/httptest" "reflect" "sort" @@ -37,7 +37,7 @@ func TestHandler_PostSchemaCluster(t *testing.T) { t.Run("PostSchema", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/schema", strings.NewReader(`{"indexes":[{"name":"blah","options":{"keys":false,"trackExistence":true},"fields":[{"name":"f1","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576}]}`))) - if w.Code != gohttp.StatusNoContent { + if w.Code != http.StatusNoContent { bod, err := io.ReadAll(w.Result().Body) if err != nil { t.Errorf("reading body: %v", err) @@ -80,7 +80,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Not Found", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/no_such_path", nil)) - if w.Code != gohttp.StatusNotFound { + if w.Code != http.StatusNotFound { t.Fatalf("invalid status: %d", w.Code) } }) @@ -88,7 +88,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("SchemaEmpty", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } body := w.Body.String() @@ -101,7 +101,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("SchemaDetailsEmpty", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema/details", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } body := w.Body.String() @@ -114,7 +114,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("PostSchema", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/schema", strings.NewReader(`{"indexes":[{"name":"blah","options":{"keys":false,"trackExistence":true},"fields":[{"name":"f1","options":{"type":"set","cacheType":"ranked","cacheSize":50000,"keys":false}}],"shardWidth":1048576}]}`))) - if w.Code != gohttp.StatusNoContent { + if w.Code != http.StatusNoContent { bod, err := io.ReadAll(w.Result().Body) if err != nil { t.Errorf("reading body: %v", err) @@ -143,7 +143,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Info", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/info", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } var details map[string]interface{} @@ -207,7 +207,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Schema", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -291,7 +291,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("SchemaDetails", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema/details", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -465,7 +465,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Status", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/status", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } ret := mustJSONDecode(t, w.Body) @@ -481,7 +481,7 @@ func TestHandler_Endpoints(t *testing.T) { // This tests the response structure, not the cluster behavior. w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/ui/shard-distribution", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -506,7 +506,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Metrics", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } }) @@ -514,7 +514,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Metrics.json", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics.json", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } mustJSONDecode(t, w.Body) @@ -533,7 +533,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Max Shard", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/internal/shards/max", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"standard":{"i0":3,"i1":0,"i2":0}}`+"\n" { t.Fatalf("unexpected body: %s", body) @@ -543,7 +543,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Shards args", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query?shards=0,1", strings.NewReader("Count(Row(f0=30))"))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d %s", w.Code, w.Body.String()) } else if body := w.Body.String(); body != `{"results":[2]}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -567,7 +567,7 @@ func TestHandler_Endpoints(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, req) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"results":[2]}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -580,7 +580,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Query args error", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query?shards=a,b", strings.NewReader("Count(Row(f0=30))"))) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"error":"invalid shard argument"}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -590,7 +590,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Query params err", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query?shards=0,1&db=sample", strings.NewReader("Count(Row(f0=30))"))) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"error":"db is not a valid argument"}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -602,7 +602,7 @@ func TestHandler_Endpoints(t *testing.T) { r := test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader("Count(Row(f0=30))")) r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -619,7 +619,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Row JSON", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader("Row(f0=30)"))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != fmt.Sprintf(`{"results":[{"columns":[%d,%d,%d]}]}`, pilosa.ShardWidth+1, pilosa.ShardWidth+2, 3*pilosa.ShardWidth+4)+"\n" { t.Fatalf("unexpected body: %s", body) @@ -631,7 +631,7 @@ func TestHandler_Endpoints(t *testing.T) { r := test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader("Row(f0=30)")) r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -646,7 +646,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Query Pairs JSON", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`TopN(f0, n=2)`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"results":[[{"id":30,"key":"","count":3},{"id":31,"key":"","count":1}]]}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -658,7 +658,7 @@ func TestHandler_Endpoints(t *testing.T) { r := test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`TopN(f0, n=2)`)) r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -673,7 +673,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Query err JSON", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`Row(row=30)`))) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"error":"executing: translating call: validating value for field \"row\": field not found"}`+"\n" { t.Fatalf("unexpected body: %q", body) @@ -685,7 +685,7 @@ func TestHandler_Endpoints(t *testing.T) { r := test.MustNewHTTPRequest("POST", "/index/i0/query", strings.NewReader(`Row(row=30)`)) r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } @@ -710,12 +710,12 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-int-ubound" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"int"}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -741,12 +741,12 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-int-ubound-min" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"int", "max": 10}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -772,12 +772,12 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-int-ubound-max" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"int", "min": -10}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -803,7 +803,7 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-int-ubound-err" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"int", "min": 10, "max": -10}}`))) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } }) @@ -813,12 +813,12 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-decimal-ubound" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"decimal", "scale": 0}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -844,13 +844,13 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-decimal-ubound-min" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"decimal", "scale": 1, "max": 10.5}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { fmt.Println(w.Body.String()) t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -875,13 +875,13 @@ func TestHandler_Endpoints(t *testing.T) { fieldName := "f-decimal-scale-only" h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"decimal", "scale": 2}}`))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { fmt.Println(w.Body.String()) t.Fatalf("unexpected status code: %d", w.Code) } w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } rsp := getSchemaResponse{} @@ -909,7 +909,7 @@ func TestHandler_Endpoints(t *testing.T) { h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName), strings.NewReader(`{"options":{"type":"decimal"}}`))) expErr := "decimal field requires a scale argument" - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } else if !strings.Contains(w.Body.String(), expErr) { t.Fatalf("expected error to contain: %s, but got: %s", expErr, w.Body.String()) @@ -919,7 +919,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Method not allowed", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/index/i0/query", nil)) - if w.Code != gohttp.StatusMethodNotAllowed { + if w.Code != http.StatusMethodNotAllowed { t.Fatalf("invalid status: %d", w.Code) } }) @@ -927,7 +927,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Err Parse", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/index/idx0/query?shards=0,1", strings.NewReader("bad_fn("))) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"error":"parsing: parsing: \nparse error near IDENT (line 1 symbol 1 - line 1 symbol 4):\n\"bad\"\n"}`+"\n" { t.Fatalf("unexpected body: %s", body) @@ -938,7 +938,7 @@ func TestHandler_Endpoints(t *testing.T) { hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{}) w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("DELETE", "/index/i", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d, body: %s", w.Code, w.Body.String()) } else { var resp struct { @@ -963,7 +963,7 @@ func TestHandler_Endpoints(t *testing.T) { } w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("DELETE", "/index/i/field/f1", strings.NewReader(""))) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d, body: %s", w.Code, w.Body.String()) } else { var resp struct { @@ -987,7 +987,7 @@ func TestHandler_Endpoints(t *testing.T) { r := test.MustNewHTTPRequest("GET", "/version", nil) h.ServeHTTP(w, r) version := strings.TrimPrefix(pilosa.Version, "v") - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else if w.Body.String() != `{"version":"`+version+`"}`+"\n" { t.Fatalf("unexpected body: %q", w.Body.String()) @@ -998,7 +998,7 @@ func TestHandler_Endpoints(t *testing.T) { w := httptest.NewRecorder() r := test.MustNewHTTPRequest("GET", "/internal/fragment/nodes?index=i&shard=0", nil) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } body := mustJSONDecodeSlice(t, w.Body) @@ -1011,7 +1011,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("GET", "/internal/fragment/nodes?db=X&shard=0", nil) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } @@ -1019,7 +1019,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("GET", "/internal/fragment/nodes?shard=0", nil) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusBadRequest { + if w.Code != http.StatusBadRequest { t.Fatalf("unexpected status code: %d", w.Code) } }) @@ -1028,7 +1028,7 @@ func TestHandler_Endpoints(t *testing.T) { w := httptest.NewRecorder() r := test.MustNewHTTPRequest("GET", "/debug/vars", nil) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } }) @@ -1036,7 +1036,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Run("Recalculate Caches", func(t *testing.T) { w := httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("POST", "/recalculate-caches", nil)) - if w.Code != gohttp.StatusNoContent { + if w.Code != http.StatusNoContent { t.Fatalf("unexpected status code: %d", w.Code) } }) @@ -1077,7 +1077,7 @@ func TestHandler_Endpoints(t *testing.T) { w := httptest.NewRecorder() r := test.MustNewHTTPRequest("POST", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1093,7 +1093,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("POST", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusConflict { + if w.Code != http.StatusConflict { t.Errorf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1111,7 +1111,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("POST", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1129,7 +1129,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("POST", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusConflict { + if w.Code != http.StatusConflict { t.Errorf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1147,7 +1147,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("DELETE", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1163,7 +1163,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("DELETE", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusNotFound { + if w.Code != http.StatusNotFound { t.Errorf("unexpected status code: %d", w.Code) } else if w.Body.String() != `{"success":false,"error":{"message":"deleting field: fld1: field not found"}}`+"\n" { t.Errorf("unexpected body: %q", w.Body.String()) @@ -1173,7 +1173,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("DELETE", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1189,7 +1189,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("DELETE", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusNotFound { + if w.Code != http.StatusNotFound { t.Errorf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1207,7 +1207,7 @@ func TestHandler_Endpoints(t *testing.T) { w := httptest.NewRecorder() r := test.MustNewHTTPRequest("POST", "/index/i1-tr", strings.NewReader(`{"options":{"keys":true}}`)) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1223,7 +1223,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("POST", "/index/i1-tr/field/f1", strings.NewReader(`{"options":{"keys":true}}`)) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } else { var resp struct { @@ -1239,7 +1239,7 @@ func TestHandler_Endpoints(t *testing.T) { w = httptest.NewRecorder() r = test.MustNewHTTPRequest("POST", "/index/i1-tr/query", strings.NewReader(`Set("col1", f1="row1")`)) h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } @@ -1257,7 +1257,7 @@ func TestHandler_Endpoints(t *testing.T) { r.Header.Set("Content-Type", "application/x-protobuf") r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } var target []uint64 @@ -1290,7 +1290,7 @@ func TestHandler_Endpoints(t *testing.T) { r.Header.Set("Content-Type", "application/x-protobuf") r.Header.Set("Accept", "application/x-protobuf") h.ServeHTTP(w, r) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) } target = []uint64{1, 2} @@ -1433,12 +1433,12 @@ func TestQueryHistory(t *testing.T) { test.Do(t, "POST", cmd.URL()+"/index/i0/query", "TopN(f0)") h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/query-history", nil)) - if w.Code != gohttp.StatusOK { + if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d %s", w.Code, w.Body.String()) } ret := make([]pilosa.PastQueryStatus, 4) - b, err := ioutil.ReadAll(w.Body) + b, err := io.ReadAll(w.Body) if err != nil { t.Fatalf("reading: %v", err) }