Skip to content

Commit

Permalink
chore: don't use deprecated ioutil package (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Mar 19, 2023
1 parent 8fcc59a commit 6ad6301
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
10 changes: 3 additions & 7 deletions clientconfig_test.go
@@ -1,7 +1,6 @@
package dns

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -91,14 +90,10 @@ func TestClientConfigFromReaderAttempts(t *testing.T) {
}

func TestReadFromFile(t *testing.T) {
tempDir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatalf("tempDir: %v", err)
}
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

path := filepath.Join(tempDir, "resolv.conf")
if err := ioutil.WriteFile(path, []byte(normal), 0644); err != nil {
if err := os.WriteFile(path, []byte(normal), 0o644); err != nil {
t.Fatalf("writeFile: %v", err)
}
cc, err := ClientConfigFromFile(path)
Expand Down Expand Up @@ -142,6 +137,7 @@ func TestNameListNdots1(t *testing.T) {
t.Errorf("NameList didn't return search last: %v", names[1])
}
}

func TestNameListNdots2(t *testing.T) {
cfg := ClientConfig{
Ndots: 2,
Expand Down
13 changes: 4 additions & 9 deletions generate_test.go
Expand Up @@ -2,30 +2,25 @@ package dns

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)

func TestGenerateRangeGuard(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "dns")
if err != nil {
t.Fatalf("could not create tmpdir for test: %v", err)
}
defer os.RemoveAll(tmpdir)
tmpdir := t.TempDir()

for i := 0; i <= 1; i++ {
path := filepath.Join(tmpdir, fmt.Sprintf("%04d.conf", i))
data := []byte(fmt.Sprintf("dhcp-%04d A 10.0.0.%d", i, i))

if err := ioutil.WriteFile(path, data, 0644); err != nil {
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatalf("could not create tmpfile for test: %v", err)
}
}

var tests = [...]struct {
tests := [...]struct {
zone string
fail bool
}{
Expand Down Expand Up @@ -85,7 +80,7 @@ $GENERATE 0-2 dhcp-${0,4,d} A 10.1.0.$
}

func TestGenerateIncludeDepth(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "dns")
tmpfile, err := os.CreateTemp("", "dns")
if err != nil {
t.Fatalf("could not create tmpfile for test: %v", err)
}
Expand Down
6 changes: 2 additions & 4 deletions scan_test.go
Expand Up @@ -2,7 +2,6 @@ package dns

import (
"io"
"io/ioutil"
"net"
"os"
"strings"
Expand Down Expand Up @@ -49,8 +48,7 @@ func TestZoneParserGenerate(t *testing.T) {
}

func TestZoneParserInclude(t *testing.T) {

tmpfile, err := ioutil.TempFile("", "dns")
tmpfile, err := os.CreateTemp("", "dns")
if err != nil {
t.Fatalf("could not create tmpfile for test: %s", err)
}
Expand Down Expand Up @@ -99,7 +97,7 @@ func TestZoneParserInclude(t *testing.T) {
}

func TestZoneParserIncludeDisallowed(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "dns")
tmpfile, err := os.CreateTemp("", "dns")
if err != nil {
t.Fatalf("could not create tmpfile for test: %s", err)
}
Expand Down

0 comments on commit 6ad6301

Please sign in to comment.