mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 00:04:15 -04:00
cleanup deprecated package io/ioutil (#4920)
Signed-off-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
|
||||
func TestAuto(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -42,7 +41,7 @@ func TestAuto(t *testing.T) {
|
||||
}
|
||||
|
||||
// Write db.example.org to get example.org.
|
||||
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -71,7 +70,7 @@ func TestAuto(t *testing.T) {
|
||||
|
||||
func TestAutoNonExistentZone(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -110,7 +109,7 @@ func TestAutoNonExistentZone(t *testing.T) {
|
||||
func TestAutoAXFR(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -138,7 +137,7 @@ func TestAutoAXFR(t *testing.T) {
|
||||
defer i.Stop()
|
||||
|
||||
// Write db.example.org to get example.org.
|
||||
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -10,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func setupProxyTargetCoreDNS(t *testing.T, fn func(string)) {
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -24,7 +23,7 @@ google.com. IN A 172.217.25.110
|
||||
`
|
||||
|
||||
path := filepath.Join(tmpdir, "file")
|
||||
if err = ioutil.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
if err = os.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
t.Fatalf("Could not write to temp file: %s", err)
|
||||
}
|
||||
defer os.Remove(path)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestZoneReload(t *testing.T) {
|
||||
}
|
||||
|
||||
// Remove RR from the Apex
|
||||
ioutil.WriteFile(name, []byte(exampleOrgUpdated), 0644)
|
||||
os.WriteFile(name, []byte(exampleOrgUpdated), 0644)
|
||||
|
||||
time.Sleep(20 * time.Millisecond) // reload time, with some race insurance
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -69,7 +68,7 @@ func TestMetricsRefused(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsAuto(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
tmpdir, err := os.MkdirTemp(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -95,7 +94,7 @@ func TestMetricsAuto(t *testing.T) {
|
||||
defer i.Stop()
|
||||
|
||||
// Write db.example.org to get example.org.
|
||||
if err = ioutil.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
if err = os.WriteFile(filepath.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(110 * time.Millisecond) // wait for it to be picked up
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -56,10 +55,10 @@ func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
|
||||
}
|
||||
|
||||
func createKeyFile(t *testing.T) func() {
|
||||
ioutil.WriteFile(base+".key",
|
||||
os.WriteFile(base+".key",
|
||||
[]byte(`example.org. IN DNSKEY 256 3 13 tDyI0uEIDO4SjhTJh1AVTFBLpKhY3He5BdAlKztewiZ7GecWj94DOodg ovpN73+oJs+UfZ+p9zOSN5usGAlHrw==`),
|
||||
0644)
|
||||
ioutil.WriteFile(base+".private",
|
||||
os.WriteFile(base+".private",
|
||||
[]byte(`Private-key-format: v1.3
|
||||
Algorithm: 13 (ECDSAP256SHA256)
|
||||
PrivateKey: HPmldSNfrkj/aDdUMFwuk/lgzaC5KIsVEG3uoYvF4pQ=
|
||||
|
||||
@@ -3,7 +3,6 @@ package test
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -52,7 +51,7 @@ func TestReadme(t *testing.T) {
|
||||
defer remove(contents)
|
||||
|
||||
middle := filepath.Join("..", "plugin")
|
||||
dirs, err := ioutil.ReadDir(middle)
|
||||
dirs, err := os.ReadDir(middle)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not read %s: %q", middle, err)
|
||||
}
|
||||
@@ -173,7 +172,7 @@ func sectionsFromReadme(readme string) error {
|
||||
|
||||
func create(c map[string]string) {
|
||||
for name, content := range c {
|
||||
ioutil.WriteFile(name, []byte(content), 0644)
|
||||
os.WriteFile(name, []byte(content), 0644)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -105,7 +105,7 @@ func TestReloadMetricsHealth(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ok, _ := ioutil.ReadAll(resp.Body)
|
||||
ok, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if string(ok) != http.StatusText(http.StatusOK) {
|
||||
t.Errorf("Failed to receive OK, got %s", ok)
|
||||
@@ -117,7 +117,7 @@ func TestReloadMetricsHealth(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const proc = "coredns_build_info"
|
||||
metrics, _ := ioutil.ReadAll(resp.Body)
|
||||
metrics, _ := io.ReadAll(resp.Body)
|
||||
if !bytes.Contains(metrics, []byte(proc)) {
|
||||
t.Errorf("Failed to see %s in metric output", proc)
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func collectMetricsInfo(addr string, procs ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metrics, _ := ioutil.ReadAll(resp.Body)
|
||||
metrics, _ := io.ReadAll(resp.Body)
|
||||
for _, p := range procs {
|
||||
if !bytes.Contains(metrics, []byte(p)) {
|
||||
return fmt.Errorf("failed to see %s in metric output \n%s", p, metrics)
|
||||
|
||||
Reference in New Issue
Block a user