diff --git a/core/ivr/vonage/vonage.go b/core/ivr/vonage/vonage.go index feb200ce1..4bbe551c3 100644 --- a/core/ivr/vonage/vonage.go +++ b/core/ivr/vonage/vonage.go @@ -9,7 +9,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "math/rand" "net/http" "net/url" @@ -105,11 +105,11 @@ func readBody(r *http.Request) ([]byte, error) { if r.Body == http.NoBody { return nil, nil } - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { return nil, nil } - r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + r.Body = io.NopCloser(bytes.NewBuffer(body)) return body, nil } @@ -333,7 +333,7 @@ func (c *client) PreprocessResume(ctx context.Context, db *sqlx.DB, rp *redis.Po } // get our recording url out - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { return nil, errors.Wrapf(err, "error reading body from request") } diff --git a/core/models/imports_test.go b/core/models/imports_test.go index a079506ac..eeea46f83 100644 --- a/core/models/imports_test.go +++ b/core/models/imports_test.go @@ -3,7 +3,7 @@ package models_test import ( "context" "encoding/json" - "io/ioutil" + "os" "sort" "strings" "testing" @@ -41,7 +41,7 @@ func TestContactImports(t *testing.T) { // give our org a country by setting country on a channel db.MustExec(`UPDATE channels_channel SET country = 'US' WHERE id = $1`, testdata.TwilioChannel.ID) - testJSON, err := ioutil.ReadFile("testdata/imports.json") + testJSON, err := os.ReadFile("testdata/imports.json") require.NoError(t, err) tcs := []struct { @@ -136,7 +136,7 @@ func TestContactImports(t *testing.T) { testJSON, err = jsonx.MarshalPretty(tcs) require.NoError(t, err) - err = ioutil.WriteFile("testdata/imports.json", testJSON, 0600) + err = os.WriteFile("testdata/imports.json", testJSON, 0600) require.NoError(t, err) } } diff --git a/core/models/orgs.go b/core/models/orgs.go index 29f4389ca..cc321afeb 100644 --- a/core/models/orgs.go +++ b/core/models/orgs.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "mime" "net/http" "path/filepath" @@ -186,7 +185,7 @@ func (o *Org) StoreAttachment(ctx context.Context, s storage.Storage, filename s prefix := config.Mailroom.S3MediaPrefix // read the content - contentBytes, err := ioutil.ReadAll(content) + contentBytes, err := io.ReadAll(content) if err != nil { return "", errors.Wrapf(err, "unable to read attachment content") } diff --git a/core/msgio/android_test.go b/core/msgio/android_test.go index d851dad88..bec6a8670 100644 --- a/core/msgio/android_test.go +++ b/core/msgio/android_test.go @@ -1,7 +1,7 @@ package msgio_test import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -29,7 +29,7 @@ type MockFCMEndpoint struct { func (m *MockFCMEndpoint) Handle(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - requestBody, _ := ioutil.ReadAll(r.Body) + requestBody, _ := io.ReadAll(r.Body) message := &fcm.Message{} jsonx.Unmarshal(requestBody, message) diff --git a/services/tickets/utils.go b/services/tickets/utils.go index 35563e10b..ed2389a56 100644 --- a/services/tickets/utils.go +++ b/services/tickets/utils.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "mime" "net/http" "path/filepath" @@ -138,7 +137,7 @@ func FetchFile(url string, headers map[string]string) (*File, error) { contentType, _, _ := mime.ParseMediaType(trace.Response.Header.Get("Content-Type")) - return &File{URL: url, ContentType: contentType, Body: ioutil.NopCloser(bytes.NewReader(trace.ResponseBody))}, nil + return &File{URL: url, ContentType: contentType, Body: io.NopCloser(bytes.NewReader(trace.ResponseBody))}, nil } // CloseTicket closes the given ticket, and creates and queues a closed event diff --git a/testsuite/elastic.go b/testsuite/elastic.go index 5f026ef4b..a9ca6e6e0 100644 --- a/testsuite/elastic.go +++ b/testsuite/elastic.go @@ -1,7 +1,7 @@ package testsuite import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" ) @@ -42,7 +42,7 @@ func NewMockElasticServer() *MockElasticServer { } // otherwise read our next body and return our next response - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) mock.LastBody = string(body) w.WriteHeader(200) diff --git a/web/contact/search_test.go b/web/contact/search_test.go index b884e96f4..7250c762c 100644 --- a/web/contact/search_test.go +++ b/web/contact/search_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "sync" "testing" @@ -213,7 +212,7 @@ func TestSearch(t *testing.T) { assert.Equal(t, tc.ExpectedStatus, resp.StatusCode, "%d: unexpected status", i) - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) assert.NoError(t, err, "%d: error reading body", i) // on 200 responses parse them diff --git a/web/ivr/ivr_test.go b/web/ivr/ivr_test.go index 143d25d09..ba7fa3d8c 100644 --- a/web/ivr/ivr_test.go +++ b/web/ivr/ivr_test.go @@ -3,7 +3,7 @@ package ivr import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -253,7 +253,7 @@ func TestTwilioIVR(t *testing.T) { require.NoError(t, err) assert.Equal(t, tc.expectedStatus, resp.StatusCode, "status code mismatch in %s", tc.label) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) if tc.expectedResponse != "" { assert.Equal(t, ``+"\n"+tc.expectedResponse, string(body), "response mismatch in %s", tc.label) @@ -313,7 +313,7 @@ func TestVonageIVR(t *testing.T) { } `json:"to"` Action string `json:"action,omitempty"` } - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) form := &CallForm{} json.Unmarshal(body, form) logrus.WithField("method", r.Method).WithField("url", r.URL.String()).WithField("body", string(body)).WithField("form", form).Info("test server called") @@ -377,10 +377,6 @@ func TestVonageIVR(t *testing.T) { tcs := []struct { label string url string - action string - channel *testdata.Channel - connectionID models.ConnectionID - form url.Values body string expectedStatus int expectedResponse string @@ -424,14 +420,14 @@ func TestVonageIVR(t *testing.T) { contains: []string{"Great! You said One."}, }, { - label: "dtmf too large", + label: "handle resume with digits out of range in flow", url: fmt.Sprintf("/ivr/c/%s/handle?action=resume&connection=1&wait_type=gather", testdata.VonageChannel.UUID), body: `{"dtmf":"101","timed_out":false,"uuid":null,"conversation_uuid":"CON-f90649c3-cbf3-42d6-9ab1-01503befac1c","timestamp":"2019-04-01T21:08:54.680Z"}`, expectedStatus: 200, contains: []string{"too big"}, }, { - label: "dtmf 56", + label: "handle resume with digits within range in flow", url: fmt.Sprintf("/ivr/c/%s/handle?action=resume&connection=1&wait_type=gather", testdata.VonageChannel.UUID), body: `{"dtmf":"56","timed_out":false,"uuid":null,"conversation_uuid":"CON-f90649c3-cbf3-42d6-9ab1-01503befac1c","timestamp":"2019-04-01T21:08:54.680Z"}`, expectedStatus: 200, @@ -558,7 +554,7 @@ func TestVonageIVR(t *testing.T) { require.NoError(t, err) assert.Equal(t, tc.expectedStatus, resp.StatusCode, "status code mismatch in %s", tc.label) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) if tc.expectedResponse != "" { test.AssertEqualJSON(t, []byte(tc.expectedResponse), body, "response mismatch in %s", tc.label) diff --git a/web/org/metrics_test.go b/web/org/metrics_test.go index 10943425e..63133b4ed 100644 --- a/web/org/metrics_test.go +++ b/web/org/metrics_test.go @@ -2,7 +2,7 @@ package org_test import ( "fmt" - "io/ioutil" + "io" "net/http" "sync" "testing" @@ -95,7 +95,7 @@ func TestMetrics(t *testing.T) { resp, err := http.DefaultClient.Do(req) assert.NoError(t, err, "%s: received error", tc.Label) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) if tc.Response != "" { assert.Equal(t, tc.Response, string(body), "%s: response mismatch", tc.Label) diff --git a/web/simulation/simulation_test.go b/web/simulation/simulation_test.go index bc7033772..42776a49e 100644 --- a/web/simulation/simulation_test.go +++ b/web/simulation/simulation_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "io" - "io/ioutil" "net/http" "strings" "sync" @@ -266,7 +265,7 @@ func TestServer(t *testing.T) { assert.Equal(t, tc.ExpectedStatus, resp.StatusCode, "%d: unexpected status", i) - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) assert.NoError(t, err, "%d: error reading body", i) // if this was a success, save our session diff --git a/web/surveyor/surveyor_test.go b/web/surveyor/surveyor_test.go index 3ad89b463..71839394a 100644 --- a/web/surveyor/surveyor_test.go +++ b/web/surveyor/surveyor_test.go @@ -3,8 +3,9 @@ package surveyor import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" + "os" "path/filepath" "sync" "testing" @@ -112,7 +113,7 @@ func TestSurveyor(t *testing.T) { for i, tc := range tcs { testID := fmt.Sprintf("%s[token=%s]", tc.File, tc.Token) path := filepath.Join("testdata", tc.File) - submission, err := ioutil.ReadFile(path) + submission, err := os.ReadFile(path) assert.NoError(t, err) url := "http://localhost:8090/mr/surveyor/submit" @@ -128,7 +129,7 @@ func TestSurveyor(t *testing.T) { assert.NoError(t, err) assert.Equal(t, tc.StatusCode, resp.StatusCode, "unexpected status code for %s", testID) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) assert.Containsf(t, string(body), tc.Contains, "%s does not contain expected body", testID) id, _ := jsonparser.GetInt(body, "contact", "id") diff --git a/web/testing.go b/web/testing.go index 65e506af4..2ff1317c9 100644 --- a/web/testing.go +++ b/web/testing.go @@ -6,10 +6,10 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "mime/multipart" "net/http" "net/textproto" + "os" "strings" "sync" "testing" @@ -66,7 +66,7 @@ func RunWebTests(t *testing.T, truthFile string, substitutions map[string]string actualResponse []byte } tcs := make([]*TestCase, 0, 20) - tcJSON, err := ioutil.ReadFile(truthFile) + tcJSON, err := os.ReadFile(truthFile) require.NoError(t, err) for key, value := range substitutions { @@ -126,7 +126,7 @@ func RunWebTests(t *testing.T, truthFile string, substitutions map[string]string actual.HTTPMocks = clonedMocks tc.HTTPMocks = clonedMocks - tc.actualResponse, err = ioutil.ReadAll(resp.Body) + tc.actualResponse, err = io.ReadAll(resp.Body) assert.NoError(t, err, "%s: error reading body", tc.Label) if !test.UpdateSnapshots { @@ -136,7 +136,7 @@ func RunWebTests(t *testing.T, truthFile string, substitutions map[string]string expectedIsJSON := false if tc.ResponseFile != "" { - expectedResponse, err = ioutil.ReadFile(tc.ResponseFile) + expectedResponse, err = os.ReadFile(tc.ResponseFile) require.NoError(t, err) expectedIsJSON = strings.HasSuffix(tc.ResponseFile, ".json") @@ -164,7 +164,7 @@ func RunWebTests(t *testing.T, truthFile string, substitutions map[string]string if test.UpdateSnapshots { for _, tc := range tcs { if tc.ResponseFile != "" { - err = ioutil.WriteFile(tc.ResponseFile, tc.actualResponse, 0644) + err = os.WriteFile(tc.ResponseFile, tc.actualResponse, 0644) require.NoError(t, err, "failed to update response file") } else { tc.Response = tc.actualResponse @@ -174,7 +174,7 @@ func RunWebTests(t *testing.T, truthFile string, substitutions map[string]string truth, err := jsonx.MarshalPretty(tcs) require.NoError(t, err) - err = ioutil.WriteFile(truthFile, truth, 0644) + err = os.WriteFile(truthFile, truth, 0644) require.NoError(t, err, "failed to update truth file") } }