Skip to content

Commit 90638ca

Browse files
committed
ci: replace deprecated "io/ioutil" package
1 parent 0a701e1 commit 90638ca

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

typesense/documents_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"strings"
109
"testing"
@@ -277,11 +276,11 @@ func TestDocumentsDeleteOnHttpStatusErrorCodeReturnsError(t *testing.T) {
277276
}
278277

279278
func createDocumentStream() io.ReadCloser {
280-
return ioutil.NopCloser(strings.NewReader(`{"id": "125","company_name":"Future Technology","num_employees":1232,"country":"UK"}`))
279+
return io.NopCloser(strings.NewReader(`{"id": "125","company_name":"Future Technology","num_employees":1232,"country":"UK"}`))
281280
}
282281

283282
func TestDocumentsExport(t *testing.T) {
284-
expectedBytes, err := ioutil.ReadAll(createDocumentStream())
283+
expectedBytes, err := io.ReadAll(createDocumentStream())
285284
assert.Nil(t, err)
286285

287286
ctrl := gomock.NewController(t)
@@ -301,7 +300,7 @@ func TestDocumentsExport(t *testing.T) {
301300
result, err := client.Collection("companies").Documents().Export(context.Background(), &api.ExportDocumentsParams{})
302301
assert.Nil(t, err)
303302

304-
resultBytes, err := ioutil.ReadAll(result)
303+
resultBytes, err := io.ReadAll(result)
305304
assert.Nil(t, err)
306305
assert.Equal(t, string(expectedBytes), string(resultBytes))
307306
}
@@ -330,7 +329,7 @@ func TestDocumentsExportOnHttpStatusErrorCodeReturnsError(t *testing.T) {
330329
ExportDocuments(gomock.Not(gomock.Nil()), "companies", &api.ExportDocumentsParams{}).
331330
Return(&http.Response{
332331
StatusCode: http.StatusInternalServerError,
333-
Body: ioutil.NopCloser(strings.NewReader("Internal server error")),
332+
Body: io.NopCloser(strings.NewReader("Internal server error")),
334333
}, nil).
335334
Times(1)
336335

typesense/import_test.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"errors"
77
"io"
8-
"io/ioutil"
98
"net/http"
109
"reflect"
1110
"strings"
@@ -23,7 +22,7 @@ type eqReaderMatcher struct {
2322
}
2423

2524
func eqReader(r io.Reader) gomock.Matcher {
26-
allBytes, err := ioutil.ReadAll(r)
25+
allBytes, err := io.ReadAll(r)
2726
if err != nil {
2827
panic(err)
2928
}
@@ -35,7 +34,7 @@ func (m *eqReaderMatcher) Matches(x interface{}) bool {
3534
return false
3635
}
3736
r := x.(io.Reader)
38-
allBytes, err := ioutil.ReadAll(r)
37+
allBytes, err := io.ReadAll(r)
3938
if err != nil {
4039
panic(err)
4140
}
@@ -66,7 +65,7 @@ func TestDocumentsImportWithOneDocument(t *testing.T) {
6665
"companies", expectedParams, "application/octet-stream", eqReader(expectedBody)).
6766
Return(&http.Response{
6867
StatusCode: http.StatusOK,
69-
Body: ioutil.NopCloser(strings.NewReader(expectedResultString)),
68+
Body: io.NopCloser(strings.NewReader(expectedResultString)),
7069
}, nil).
7170
Times(1)
7271

@@ -116,7 +115,7 @@ func TestDocumentsImportWithOneDocumentAndInvalidResultJsonReturnsError(t *testi
116115
"companies", expectedParams, "application/octet-stream", eqReader(expectedBody)).
117116
Return(&http.Response{
118117
StatusCode: http.StatusOK,
119-
Body: ioutil.NopCloser(strings.NewReader(expectedResultString)),
118+
Body: io.NopCloser(strings.NewReader(expectedResultString)),
120119
}, nil).
121120
Times(1)
122121

@@ -182,7 +181,7 @@ func TestDocumentsImportOnHttpStatusErrorCodeReturnsError(t *testing.T) {
182181
"companies", gomock.Any(), "application/octet-stream", gomock.Any()).
183182
Return(&http.Response{
184183
StatusCode: http.StatusInternalServerError,
185-
Body: ioutil.NopCloser(strings.NewReader("Internal server error")),
184+
Body: io.NopCloser(strings.NewReader("Internal server error")),
186185
}, nil).
187186
Times(1)
188187

@@ -220,7 +219,7 @@ func TestDocumentsImportWithTwoDocuments(t *testing.T) {
220219
"companies", expectedParams, "application/octet-stream", eqReader(expectedBody)).
221220
Return(&http.Response{
222221
StatusCode: http.StatusOK,
223-
Body: ioutil.NopCloser(strings.NewReader(expectedResultString)),
222+
Body: io.NopCloser(strings.NewReader(expectedResultString)),
224223
}, nil).
225224
Times(1)
226225

@@ -254,7 +253,7 @@ func TestDocumentsImportWithActionOnly(t *testing.T) {
254253
"companies", expectedParams, "application/octet-stream", gomock.Any()).
255254
Return(&http.Response{
256255
StatusCode: http.StatusOK,
257-
Body: ioutil.NopCloser(strings.NewReader(`{"success": true}`)),
256+
Body: io.NopCloser(strings.NewReader(`{"success": true}`)),
258257
}, nil).
259258
Times(1)
260259

@@ -284,7 +283,7 @@ func TestDocumentsImportWithBatchSizeOnly(t *testing.T) {
284283
"companies", expectedParams, "application/octet-stream", gomock.Any()).
285284
Return(&http.Response{
286285
StatusCode: http.StatusOK,
287-
Body: ioutil.NopCloser(strings.NewReader(`{"success": true}`)),
286+
Body: io.NopCloser(strings.NewReader(`{"success": true}`)),
288287
}, nil).
289288
Times(1)
290289

@@ -316,7 +315,7 @@ func TestDocumentsImportJsonl(t *testing.T) {
316315
"companies", expectedParams, "application/octet-stream", eqReader(expectedBody)).
317316
Return(&http.Response{
318317
StatusCode: http.StatusOK,
319-
Body: ioutil.NopCloser(bytes.NewBuffer(expectedBytes)),
318+
Body: io.NopCloser(bytes.NewBuffer(expectedBytes)),
320319
}, nil).
321320
Times(1)
322321

@@ -329,7 +328,7 @@ func TestDocumentsImportJsonl(t *testing.T) {
329328
result, err := client.Collection("companies").Documents().ImportJsonl(context.Background(), importBody, params)
330329
assert.Nil(t, err)
331330

332-
resultBytes, err := ioutil.ReadAll(result)
331+
resultBytes, err := io.ReadAll(result)
333332
assert.Nil(t, err)
334333
assert.Equal(t, string(expectedBytes), string(resultBytes))
335334
}
@@ -365,7 +364,7 @@ func TestDocumentsImportJsonlOnHttpStatusErrorCodeReturnsError(t *testing.T) {
365364
gomock.Any(), gomock.Any(), "application/octet-stream", gomock.Any()).
366365
Return(&http.Response{
367366
StatusCode: http.StatusInternalServerError,
368-
Body: ioutil.NopCloser(strings.NewReader("Internal server error")),
367+
Body: io.NopCloser(strings.NewReader("Internal server error")),
369368
}, nil).
370369
Times(1)
371370

@@ -394,7 +393,7 @@ func TestDocumentsImportJsonlWithActionOnly(t *testing.T) {
394393
"companies", expectedParams, "application/octet-stream", gomock.Any()).
395394
Return(&http.Response{
396395
StatusCode: http.StatusOK,
397-
Body: ioutil.NopCloser(strings.NewReader(`{"success": true}`)),
396+
Body: io.NopCloser(strings.NewReader(`{"success": true}`)),
398397
}, nil).
399398
Times(1)
400399

@@ -422,7 +421,7 @@ func TestDocumentsImportJsonlWithBatchSizeOnly(t *testing.T) {
422421
"companies", expectedParams, "application/octet-stream", gomock.Any()).
423422
Return(&http.Response{
424423
StatusCode: http.StatusOK,
425-
Body: ioutil.NopCloser(strings.NewReader(`{"success": true}`)),
424+
Body: io.NopCloser(strings.NewReader(`{"success": true}`)),
426425
}, nil).
427426
Times(1)
428427

0 commit comments

Comments
 (0)