mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
CHORE: Remove deprecated io/ioutil (#1699)
* Remove deprecated io/ioutil * fixup! * fixup!
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
_ "embed" // Used to embed helpers.js in the binary.
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -40,7 +39,7 @@ var EnableFetch bool = false
|
||||
|
||||
// ExecuteJavascript accepts a javascript string and runs it, returning the resulting dnsConfig.
|
||||
func ExecuteJavascript(file string, devMode bool, variables map[string]string) (*models.DNSConfig, error) {
|
||||
script, err := ioutil.ReadFile(file)
|
||||
script, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -111,7 +110,7 @@ func ExecuteJavascript(file string, devMode bool, variables map[string]string) (
|
||||
func GetHelpers(devMode bool) string {
|
||||
if devMode {
|
||||
// Load the file:
|
||||
b, err := ioutil.ReadFile(helpersJsFileName)
|
||||
b, err := os.ReadFile(helpersJsFileName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -143,7 +142,7 @@ func require(call otto.FunctionCall) otto.Value {
|
||||
|
||||
printer.Debugf("requiring: %s (%s)\n", file, relFile)
|
||||
// quick fix, by replacing to linux slashes, to make it work with windows paths too.
|
||||
data, err := ioutil.ReadFile(filepath.ToSlash(relFile))
|
||||
data, err := os.ReadFile(filepath.ToSlash(relFile))
|
||||
|
||||
if err != nil {
|
||||
throw(call.Otto, err.Error())
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -28,7 +27,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestParsedFiles(t *testing.T) {
|
||||
files, err := ioutil.ReadDir(testDir)
|
||||
files, err := os.ReadDir(testDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func TestParsedFiles(t *testing.T) {
|
||||
}
|
||||
testName := name[:len(name)-3]
|
||||
expectedFile := filepath.Join(testDir, testName+".json")
|
||||
expectedJSON, err := ioutil.ReadFile(expectedFile)
|
||||
expectedJSON, err := os.ReadFile(expectedFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -88,7 +87,7 @@ func TestParsedFiles(t *testing.T) {
|
||||
as := string(actualJSON)
|
||||
_, _ = es, as
|
||||
// When debugging, leave behind the actual result:
|
||||
//ioutil.WriteFile(expectedFile+".ACTUAL", []byte(es), 0644)
|
||||
// os.WriteFile(expectedFile+".ACTUAL", []byte(es), 0644)
|
||||
testifyrequire.JSONEqf(t, es, as, "EXPECTING %q = \n```\n%s\n```", expectedFile, as)
|
||||
|
||||
// For each domain, if there is a zone file, test against it:
|
||||
@@ -101,7 +100,7 @@ func TestParsedFiles(t *testing.T) {
|
||||
var dCount int
|
||||
for _, dc := range conf.Domains {
|
||||
zoneFile := filepath.Join(testDir, testName, dc.Name+".zone")
|
||||
expectedZone, err := ioutil.ReadFile(zoneFile)
|
||||
expectedZone, err := os.ReadFile(zoneFile)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -119,7 +118,7 @@ func TestParsedFiles(t *testing.T) {
|
||||
as := actualZone
|
||||
if es != as {
|
||||
// On failure, leave behind the .ACTUAL file.
|
||||
ioutil.WriteFile(zoneFile+".ACTUAL", []byte(actualZone), 0644)
|
||||
os.WriteFile(zoneFile+".ACTUAL", []byte(actualZone), 0644)
|
||||
}
|
||||
testifyrequire.Equal(t, es, as, "EXPECTING %q =\n```\n%s```", zoneFile, as)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user