all: Remove usage of deprecated io/ioutil (#7971)

As of Go 1.16 io/ioutil is deprecated. This replaces usage with the
corresponding functions in package os and package io.
This commit is contained in:
Jakob Borg
2021-11-22 08:59:47 +01:00
committed by GitHub
parent bf89bffb0b
commit 4b750b6dc3
71 changed files with 190 additions and 235 deletions
+6 -7
View File
@@ -13,7 +13,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@@ -223,7 +222,7 @@ func expectURLToContain(t *testing.T, url, exp string) {
return
}
data, err := ioutil.ReadAll(res.Body)
data, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Error(err)
@@ -508,7 +507,7 @@ func testHTTPRequest(t *testing.T, baseURL string, tc httpTestCase, apikey strin
return
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Unexpected error reading %s: %v", tc.URL, err)
return
@@ -1137,7 +1136,7 @@ func TestBrowse(t *testing.T) {
pathSep := string(os.PathSeparator)
tmpDir, err := ioutil.TempDir("", "syncthing")
tmpDir, err := os.MkdirTemp("", "syncthing")
if err != nil {
t.Fatal(err)
}
@@ -1146,7 +1145,7 @@ func TestBrowse(t *testing.T) {
if err := os.Mkdir(filepath.Join(tmpDir, "dir"), 0755); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(tmpDir, "file"), []byte("hello"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, "file"), []byte("hello"), 0644); err != nil {
t.Fatal(err)
}
if err := os.Mkdir(filepath.Join(tmpDir, "MiXEDCase"), 0755); err != nil {
@@ -1251,7 +1250,7 @@ func TestConfigChanges(t *testing.T) {
APIKey: testAPIKey,
},
}
tmpFile, err := ioutil.TempFile("", "syncthing-testConfig-")
tmpFile, err := os.CreateTemp("", "syncthing-testConfig-")
if err != nil {
panic(err)
}
@@ -1393,7 +1392,7 @@ func runningInContainer() bool {
return false
}
bs, err := ioutil.ReadFile("/proc/1/cgroup")
bs, err := os.ReadFile("/proc/1/cgroup")
if err != nil {
return false
}