Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
5191959b
Commit
5191959b
authored
Oct 13, 2021
by
Zou Nengren
Committed by
GitHub
Oct 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup deprecated package io/ioutil (#4920)
Signed-off-by:
zounengren
<
zouyee1989@gmail.com
>
parent
44fcca0e
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
53 additions
and
72 deletions
+53
-72
coremain/run.go
coremain/run.go
+2
-3
directives_generate.go
directives_generate.go
+1
-2
owners_generate.go
owners_generate.go
+1
-2
plugin/auto/walk_test.go
plugin/auto/walk_test.go
+2
-3
plugin/dnssec/setup_test.go
plugin/dnssec/setup_test.go
+4
-5
plugin/file/reload_test.go
plugin/file/reload_test.go
+1
-2
plugin/forward/setup_test.go
plugin/forward/setup_test.go
+1
-2
plugin/grpc/setup_test.go
plugin/grpc/setup_test.go
+1
-2
plugin/health/health_test.go
plugin/health/health_test.go
+2
-2
plugin/log/log_test.go
plugin/log/log_test.go
+2
-2
plugin/pkg/doh/doh.go
plugin/pkg/doh/doh.go
+1
-2
plugin/pkg/log/log.go
plugin/pkg/log/log.go
+2
-2
plugin/pkg/parse/host_test.go
plugin/pkg/parse/host_test.go
+1
-2
plugin/pkg/tls/tls.go
plugin/pkg/tls/tls.go
+2
-2
plugin/root/root_test.go
plugin/root/root_test.go
+1
-2
plugin/sign/file.go
plugin/sign/file.go
+1
-2
plugin/sign/keys.go
plugin/sign/keys.go
+2
-2
plugin/sign/signer_test.go
plugin/sign/signer_test.go
+1
-2
plugin/test/file.go
plugin/test/file.go
+6
-7
test/auto_test.go
test/auto_test.go
+5
-6
test/erratic_autopath_test.go
test/erratic_autopath_test.go
+2
-3
test/file_reload_test.go
test/file_reload_test.go
+2
-2
test/metrics_test.go
test/metrics_test.go
+2
-3
test/plugin_dnssec_test.go
test/plugin_dnssec_test.go
+2
-3
test/readme_test.go
test/readme_test.go
+2
-3
test/reload_test.go
test/reload_test.go
+4
-4
No files found.
coremain/run.go
View file @
5191959b
...
@@ -4,7 +4,6 @@ package coremain
...
@@ -4,7 +4,6 @@ package coremain
import
(
import
(
"flag"
"flag"
"fmt"
"fmt"
"io/ioutil"
"log"
"log"
"os"
"os"
"runtime"
"runtime"
...
@@ -96,7 +95,7 @@ func confLoader(serverType string) (caddy.Input, error) {
...
@@ -96,7 +95,7 @@ func confLoader(serverType string) (caddy.Input, error) {
return
caddy
.
CaddyfileFromPipe
(
os
.
Stdin
,
serverType
)
return
caddy
.
CaddyfileFromPipe
(
os
.
Stdin
,
serverType
)
}
}
contents
,
err
:=
ioutil
.
ReadFile
(
conf
)
contents
,
err
:=
os
.
ReadFile
(
conf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -109,7 +108,7 @@ func confLoader(serverType string) (caddy.Input, error) {
...
@@ -109,7 +108,7 @@ func confLoader(serverType string) (caddy.Input, error) {
// defaultLoader loads the Corefile from the current working directory.
// defaultLoader loads the Corefile from the current working directory.
func
defaultLoader
(
serverType
string
)
(
caddy
.
Input
,
error
)
{
func
defaultLoader
(
serverType
string
)
(
caddy
.
Input
,
error
)
{
contents
,
err
:=
ioutil
.
ReadFile
(
caddy
.
DefaultConfigFile
)
contents
,
err
:=
os
.
ReadFile
(
caddy
.
DefaultConfigFile
)
if
err
!=
nil
{
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
return
nil
,
nil
return
nil
,
nil
...
...
directives_generate.go
View file @
5191959b
...
@@ -5,7 +5,6 @@ package main
...
@@ -5,7 +5,6 @@ package main
import
(
import
(
"bufio"
"bufio"
"go/format"
"go/format"
"io/ioutil"
"log"
"log"
"os"
"os"
"strings"
"strings"
...
@@ -101,7 +100,7 @@ func formatAndWrite(file string, data string) error {
...
@@ -101,7 +100,7 @@ func formatAndWrite(file string, data string) error {
return
err
return
err
}
}
if
err
=
ioutil
.
WriteFile
(
file
,
res
,
0644
);
err
!=
nil
{
if
err
=
os
.
WriteFile
(
file
,
res
,
0644
);
err
!=
nil
{
return
err
return
err
}
}
return
nil
return
nil
...
...
owners_generate.go
View file @
5191959b
...
@@ -7,7 +7,6 @@ package main
...
@@ -7,7 +7,6 @@ package main
import
(
import
(
"bufio"
"bufio"
"fmt"
"fmt"
"io/ioutil"
"log"
"log"
"os"
"os"
"sort"
"sort"
...
@@ -35,7 +34,7 @@ var Owners = []string{`
...
@@ -35,7 +34,7 @@ var Owners = []string{`
// to prevent `No newline at end of file` with gofmt
// to prevent `No newline at end of file` with gofmt
golist
+=
"
\n
"
golist
+=
"
\n
"
if
err
:=
ioutil
.
WriteFile
(
"plugin/chaos/zowners.go"
,
[]
byte
(
golist
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"plugin/chaos/zowners.go"
,
[]
byte
(
golist
),
0644
);
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
return
return
...
...
plugin/auto/walk_test.go
View file @
5191959b
package
auto
package
auto
import
(
import
(
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
...
@@ -67,13 +66,13 @@ func TestWalkNonExistent(t *testing.T) {
...
@@ -67,13 +66,13 @@ func TestWalkNonExistent(t *testing.T) {
}
}
func
createFiles
()
(
string
,
error
)
{
func
createFiles
()
(
string
,
error
)
{
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"coredns"
)
dir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"coredns"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
dir
,
err
return
dir
,
err
}
}
for
_
,
name
:=
range
dbFiles
{
for
_
,
name
:=
range
dbFiles
{
if
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
name
),
[]
byte
(
zoneContent
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
filepath
.
Join
(
dir
,
name
),
[]
byte
(
zoneContent
),
0644
);
err
!=
nil
{
return
dir
,
err
return
dir
,
err
}
}
}
}
...
...
plugin/dnssec/setup_test.go
View file @
5191959b
package
dnssec
package
dnssec
import
(
import
(
"io/ioutil"
"os"
"os"
"strings"
"strings"
"testing"
"testing"
...
@@ -10,19 +9,19 @@ import (
...
@@ -10,19 +9,19 @@ import (
)
)
func
TestSetupDnssec
(
t
*
testing
.
T
)
{
func
TestSetupDnssec
(
t
*
testing
.
T
)
{
if
err
:=
ioutil
.
WriteFile
(
"Kcluster.local.key"
,
[]
byte
(
keypub
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"Kcluster.local.key"
,
[]
byte
(
keypub
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write pub key file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write pub key file: %s"
,
err
)
}
}
defer
func
()
{
os
.
Remove
(
"Kcluster.local.key"
)
}()
defer
func
()
{
os
.
Remove
(
"Kcluster.local.key"
)
}()
if
err
:=
ioutil
.
WriteFile
(
"Kcluster.local.private"
,
[]
byte
(
keypriv
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"Kcluster.local.private"
,
[]
byte
(
keypriv
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write private key file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write private key file: %s"
,
err
)
}
}
defer
func
()
{
os
.
Remove
(
"Kcluster.local.private"
)
}()
defer
func
()
{
os
.
Remove
(
"Kcluster.local.private"
)
}()
if
err
:=
ioutil
.
WriteFile
(
"ksk_Kcluster.local.key"
,
[]
byte
(
kskpub
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"ksk_Kcluster.local.key"
,
[]
byte
(
kskpub
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write pub key file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write pub key file: %s"
,
err
)
}
}
defer
func
()
{
os
.
Remove
(
"ksk_Kcluster.local.key"
)
}()
defer
func
()
{
os
.
Remove
(
"ksk_Kcluster.local.key"
)
}()
if
err
:=
ioutil
.
WriteFile
(
"ksk_Kcluster.local.private"
,
[]
byte
(
kskpriv
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"ksk_Kcluster.local.private"
,
[]
byte
(
kskpriv
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write private key file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write private key file: %s"
,
err
)
}
}
defer
func
()
{
os
.
Remove
(
"ksk_Kcluster.local.private"
)
}()
defer
func
()
{
os
.
Remove
(
"ksk_Kcluster.local.private"
)
}()
...
...
plugin/file/reload_test.go
View file @
5191959b
...
@@ -2,7 +2,6 @@ package file
...
@@ -2,7 +2,6 @@ package file
import
(
import
(
"context"
"context"
"io/ioutil"
"os"
"os"
"strings"
"strings"
"testing"
"testing"
...
@@ -56,7 +55,7 @@ func TestZoneReload(t *testing.T) {
...
@@ -56,7 +55,7 @@ func TestZoneReload(t *testing.T) {
if
len
(
rrs
)
!=
5
{
if
len
(
rrs
)
!=
5
{
t
.
Fatalf
(
"Expected 5 RRs, got %d"
,
len
(
rrs
))
t
.
Fatalf
(
"Expected 5 RRs, got %d"
,
len
(
rrs
))
}
}
if
err
:=
ioutil
.
WriteFile
(
fileName
,
[]
byte
(
reloadZone2Test
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
fileName
,
[]
byte
(
reloadZone2Test
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write new zone data: %s"
,
err
)
t
.
Fatalf
(
"Failed to write new zone data: %s"
,
err
)
}
}
// Could still be racy, but we need to wait a bit for the event to be seen
// Could still be racy, but we need to wait a bit for the event to be seen
...
...
plugin/forward/setup_test.go
View file @
5191959b
package
forward
package
forward
import
(
import
(
"io/ioutil"
"os"
"os"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -126,7 +125,7 @@ func TestSetupTLS(t *testing.T) {
...
@@ -126,7 +125,7 @@ func TestSetupTLS(t *testing.T) {
func
TestSetupResolvconf
(
t
*
testing
.
T
)
{
func
TestSetupResolvconf
(
t
*
testing
.
T
)
{
const
resolv
=
"resolv.conf"
const
resolv
=
"resolv.conf"
if
err
:=
ioutil
.
WriteFile
(
resolv
,
if
err
:=
os
.
WriteFile
(
resolv
,
[]
byte
(
`nameserver 10.10.255.252
[]
byte
(
`nameserver 10.10.255.252
nameserver 10.10.255.253`
),
0666
);
err
!=
nil
{
nameserver 10.10.255.253`
),
0666
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write resolv.conf file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write resolv.conf file: %s"
,
err
)
...
...
plugin/grpc/setup_test.go
View file @
5191959b
package
grpc
package
grpc
import
(
import
(
"io/ioutil"
"os"
"os"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -105,7 +104,7 @@ tls
...
@@ -105,7 +104,7 @@ tls
func
TestSetupResolvconf
(
t
*
testing
.
T
)
{
func
TestSetupResolvconf
(
t
*
testing
.
T
)
{
const
resolv
=
"resolv.conf"
const
resolv
=
"resolv.conf"
if
err
:=
ioutil
.
WriteFile
(
resolv
,
if
err
:=
os
.
WriteFile
(
resolv
,
[]
byte
(
`nameserver 10.10.255.252
[]
byte
(
`nameserver 10.10.255.252
nameserver 10.10.255.253`
),
0666
);
err
!=
nil
{
nameserver 10.10.255.253`
),
0666
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to write resolv.conf file: %s"
,
err
)
t
.
Fatalf
(
"Failed to write resolv.conf file: %s"
,
err
)
...
...
plugin/health/health_test.go
View file @
5191959b
...
@@ -2,7 +2,7 @@ package health
...
@@ -2,7 +2,7 @@ package health
import
(
import
(
"fmt"
"fmt"
"io
/ioutil
"
"io"
"net/http"
"net/http"
"testing"
"testing"
"time"
"time"
...
@@ -25,7 +25,7 @@ func TestHealth(t *testing.T) {
...
@@ -25,7 +25,7 @@ func TestHealth(t *testing.T) {
if
response
.
StatusCode
!=
200
{
if
response
.
StatusCode
!=
200
{
t
.
Errorf
(
"Invalid status code: expecting '200', got '%d'"
,
response
.
StatusCode
)
t
.
Errorf
(
"Invalid status code: expecting '200', got '%d'"
,
response
.
StatusCode
)
}
}
content
,
err
:=
io
util
.
ReadAll
(
response
.
Body
)
content
,
err
:=
io
.
ReadAll
(
response
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unable to get response body from %s: %v"
,
address
,
err
)
t
.
Fatalf
(
"Unable to get response body from %s: %v"
,
address
,
err
)
}
}
...
...
plugin/log/log_test.go
View file @
5191959b
...
@@ -3,7 +3,7 @@ package log
...
@@ -3,7 +3,7 @@ package log
import
(
import
(
"bytes"
"bytes"
"context"
"context"
"io
/ioutil
"
"io"
"log"
"log"
"strings"
"strings"
"testing"
"testing"
...
@@ -240,7 +240,7 @@ func TestLogged(t *testing.T) {
...
@@ -240,7 +240,7 @@ func TestLogged(t *testing.T) {
}
}
func
BenchmarkLogged
(
b
*
testing
.
B
)
{
func
BenchmarkLogged
(
b
*
testing
.
B
)
{
log
.
SetOutput
(
io
util
.
Discard
)
log
.
SetOutput
(
io
.
Discard
)
rule
:=
Rule
{
rule
:=
Rule
{
NameScope
:
"."
,
NameScope
:
"."
,
...
...
plugin/pkg/doh/doh.go
View file @
5191959b
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/base64"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"net/http"
"net/http"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -93,7 +92,7 @@ func requestToMsgGet(req *http.Request) (*dns.Msg, error) {
...
@@ -93,7 +92,7 @@ func requestToMsgGet(req *http.Request) (*dns.Msg, error) {
}
}
func
toMsg
(
r
io
.
ReadCloser
)
(
*
dns
.
Msg
,
error
)
{
func
toMsg
(
r
io
.
ReadCloser
)
(
*
dns
.
Msg
,
error
)
{
buf
,
err
:=
io
util
.
ReadAll
(
r
)
buf
,
err
:=
io
.
ReadAll
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/pkg/log/log.go
View file @
5191959b
...
@@ -10,7 +10,7 @@ package log
...
@@ -10,7 +10,7 @@ package log
import
(
import
(
"fmt"
"fmt"
"io
/ioutil
"
"io"
golog
"log"
golog
"log"
"os"
"os"
"sync"
"sync"
...
@@ -102,7 +102,7 @@ func Fatal(v ...interface{}) { log(fatal, v...); os.Exit(1) }
...
@@ -102,7 +102,7 @@ func Fatal(v ...interface{}) { log(fatal, v...); os.Exit(1) }
func
Fatalf
(
format
string
,
v
...
interface
{})
{
logf
(
fatal
,
format
,
v
...
);
os
.
Exit
(
1
)
}
func
Fatalf
(
format
string
,
v
...
interface
{})
{
logf
(
fatal
,
format
,
v
...
);
os
.
Exit
(
1
)
}
// Discard sets the log output to /dev/null.
// Discard sets the log output to /dev/null.
func
Discard
()
{
golog
.
SetOutput
(
io
util
.
Discard
)
}
func
Discard
()
{
golog
.
SetOutput
(
io
.
Discard
)
}
const
(
const
(
debug
=
"[DEBUG] "
debug
=
"[DEBUG] "
...
...
plugin/pkg/parse/host_test.go
View file @
5191959b
package
parse
package
parse
import
(
import
(
"io/ioutil"
"os"
"os"
"testing"
"testing"
...
@@ -61,7 +60,7 @@ func TestHostPortOrFile(t *testing.T) {
...
@@ -61,7 +60,7 @@ func TestHostPortOrFile(t *testing.T) {
},
},
}
}
err
:=
ioutil
.
WriteFile
(
"resolv.conf"
,
[]
byte
(
"nameserver 127.0.0.1
\n
"
),
0600
)
err
:=
os
.
WriteFile
(
"resolv.conf"
,
[]
byte
(
"nameserver 127.0.0.1
\n
"
),
0600
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to write test resolv.conf"
)
t
.
Fatalf
(
"Failed to write test resolv.conf"
)
}
}
...
...
plugin/pkg/tls/tls.go
View file @
5191959b
...
@@ -4,9 +4,9 @@ import (
...
@@ -4,9 +4,9 @@ import (
"crypto/tls"
"crypto/tls"
"crypto/x509"
"crypto/x509"
"fmt"
"fmt"
"io/ioutil"
"net"
"net"
"net/http"
"net/http"
"os"
"time"
"time"
)
)
...
@@ -95,7 +95,7 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
...
@@ -95,7 +95,7 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
}
}
roots
:=
x509
.
NewCertPool
()
roots
:=
x509
.
NewCertPool
()
pem
,
err
:=
ioutil
.
ReadFile
(
caPath
)
pem
,
err
:=
os
.
ReadFile
(
caPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error reading %s: %s"
,
caPath
,
err
)
return
nil
,
fmt
.
Errorf
(
"error reading %s: %s"
,
caPath
,
err
)
}
}
...
...
plugin/root/root_test.go
View file @
5191959b
...
@@ -2,7 +2,6 @@ package root
...
@@ -2,7 +2,6 @@ package root
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -24,7 +23,7 @@ func TestRoot(t *testing.T) {
...
@@ -24,7 +23,7 @@ func TestRoot(t *testing.T) {
nonExistingDir
:=
filepath
.
Join
(
existingDirPath
,
"highly_unlikely_to_exist_dir"
)
nonExistingDir
:=
filepath
.
Join
(
existingDirPath
,
"highly_unlikely_to_exist_dir"
)
existingFile
,
err
:=
ioutil
.
TempFile
(
""
,
"root_test"
)
existingFile
,
err
:=
os
.
CreateTemp
(
""
,
"root_test"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"BeforeTest: Failed to create temp file for testing! Error was: %v"
,
err
)
t
.
Fatalf
(
"BeforeTest: Failed to create temp file for testing! Error was: %v"
,
err
)
}
}
...
...
plugin/sign/file.go
View file @
5191959b
...
@@ -3,7 +3,6 @@ package sign
...
@@ -3,7 +3,6 @@ package sign
import
(
import
(
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
...
@@ -15,7 +14,7 @@ import (
...
@@ -15,7 +14,7 @@ import (
// write writes out the zone file to a temporary file which is then moved into the correct place.
// write writes out the zone file to a temporary file which is then moved into the correct place.
func
(
s
*
Signer
)
write
(
z
*
file
.
Zone
)
error
{
func
(
s
*
Signer
)
write
(
z
*
file
.
Zone
)
error
{
f
,
err
:=
ioutil
.
TempFile
(
s
.
directory
,
"signed-"
)
f
,
err
:=
os
.
CreateTemp
(
s
.
directory
,
"signed-"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/sign/keys.go
View file @
5191959b
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"crypto/ecdsa"
"crypto/ecdsa"
"crypto/rsa"
"crypto/rsa"
"fmt"
"fmt"
"io
/ioutil
"
"io"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
...
@@ -70,7 +70,7 @@ func readKeyPair(public, private string) (Pair, error) {
...
@@ -70,7 +70,7 @@ func readKeyPair(public, private string) (Pair, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
Pair
{},
err
return
Pair
{},
err
}
}
b
,
err
:=
io
util
.
ReadAll
(
rk
)
b
,
err
:=
io
.
ReadAll
(
rk
)
if
err
!=
nil
{
if
err
!=
nil
{
return
Pair
{},
err
return
Pair
{},
err
}
}
...
...
plugin/sign/signer_test.go
View file @
5191959b
package
sign
package
sign
import
(
import
(
"io/ioutil"
"os"
"os"
"testing"
"testing"
"time"
"time"
...
@@ -50,7 +49,7 @@ $ORIGIN example.org.
...
@@ -50,7 +49,7 @@ $ORIGIN example.org.
@ IN SOA linode miek.miek.nl. ( 1282630060 4H 1H 7D 4H )
@ IN SOA linode miek.miek.nl. ( 1282630060 4H 1H 7D 4H )
IN NS linode
IN NS linode
`
`
if
err
:=
ioutil
.
WriteFile
(
"db.apex-test.example.org"
,
[]
byte
(
apex
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
"db.apex-test.example.org"
,
[]
byte
(
apex
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
defer
os
.
Remove
(
"db.apex-test.example.org"
)
defer
os
.
Remove
(
"db.apex-test.example.org"
)
...
...
plugin/test/file.go
View file @
5191959b
package
test
package
test
import
(
import
(
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
)
)
// TempFile will create a temporary file on disk and returns the name and a cleanup function to remove it later.
// TempFile will create a temporary file on disk and returns the name and a cleanup function to remove it later.
func
TempFile
(
dir
,
content
string
)
(
string
,
func
(),
error
)
{
func
TempFile
(
dir
,
content
string
)
(
string
,
func
(),
error
)
{
f
,
err
:=
ioutil
.
TempFile
(
dir
,
"go-test-tmpfile"
)
f
,
err
:=
os
.
CreateTemp
(
dir
,
"go-test-tmpfile"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
if
err
:=
ioutil
.
WriteFile
(
f
.
Name
(),
[]
byte
(
content
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
f
.
Name
(),
[]
byte
(
content
),
0644
);
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
rmFunc
:=
func
()
{
os
.
Remove
(
f
.
Name
())
}
rmFunc
:=
func
()
{
os
.
Remove
(
f
.
Name
())
}
...
@@ -21,7 +20,7 @@ func TempFile(dir, content string) (string, func(), error) {
...
@@ -21,7 +20,7 @@ func TempFile(dir, content string) (string, func(), error) {
// WritePEMFiles creates a tmp dir with ca.pem, cert.pem, and key.pem and the func to remove it
// WritePEMFiles creates a tmp dir with ca.pem, cert.pem, and key.pem and the func to remove it
func
WritePEMFiles
(
dir
string
)
(
string
,
func
(),
error
)
{
func
WritePEMFiles
(
dir
string
)
(
string
,
func
(),
error
)
{
tempDir
,
err
:=
ioutil
.
TempDir
(
dir
,
"go-test-pemfiles"
)
tempDir
,
err
:=
os
.
MkdirTemp
(
dir
,
"go-test-pemfiles"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -45,7 +44,7 @@ xGbtCkhVk2VQ+BiCWnjYXJ6ZMzabP7wiOFDP9Pvr2ik22PRItsW/TLfHFXM1jDmc
...
@@ -45,7 +44,7 @@ xGbtCkhVk2VQ+BiCWnjYXJ6ZMzabP7wiOFDP9Pvr2ik22PRItsW/TLfHFXM1jDmc
I1rs/VUGKzcJGVIWbHrgjP68CTStGAvKgbsTqw7aLXTSqtPw88N9XVSyRg==
I1rs/VUGKzcJGVIWbHrgjP68CTStGAvKgbsTqw7aLXTSqtPw88N9XVSyRg==
-----END CERTIFICATE-----`
-----END CERTIFICATE-----`
path
:=
filepath
.
Join
(
tempDir
,
"ca.pem"
)
path
:=
filepath
.
Join
(
tempDir
,
"ca.pem"
)
if
err
:=
ioutil
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
data
=
`-----BEGIN CERTIFICATE-----
data
=
`-----BEGIN CERTIFICATE-----
...
@@ -66,7 +65,7 @@ zhDEPP4FhY+Sz+y1yWirphl7A1aZwhXVPcfWIGqpQ3jzNwUeocbH27kuLh+U4hQo
...
@@ -66,7 +65,7 @@ zhDEPP4FhY+Sz+y1yWirphl7A1aZwhXVPcfWIGqpQ3jzNwUeocbH27kuLh+U4hQo
qeg10RdFnw==
qeg10RdFnw==
-----END CERTIFICATE-----`
-----END CERTIFICATE-----`
path
=
filepath
.
Join
(
tempDir
,
"cert.pem"
)
path
=
filepath
.
Join
(
tempDir
,
"cert.pem"
)
if
err
=
ioutil
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
if
err
=
os
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
@@ -98,7 +97,7 @@ E/WObVJXDnBdViu0L9abE9iaTToBVri4cmlDlZagLuKVR+TFTCN/DSlVZTDkqkLI
...
@@ -98,7 +97,7 @@ E/WObVJXDnBdViu0L9abE9iaTToBVri4cmlDlZagLuKVR+TFTCN/DSlVZTDkqkLI
8chzqtkH6b2b2R73hyRysWjsomys34ma3mEEPTX/aXeAF2MSZ/EWT9yL
8chzqtkH6b2b2R73hyRysWjsomys34ma3mEEPTX/aXeAF2MSZ/EWT9yL
-----END RSA PRIVATE KEY-----`
-----END RSA PRIVATE KEY-----`
path
=
filepath
.
Join
(
tempDir
,
"key.pem"
)
path
=
filepath
.
Join
(
tempDir
,
"key.pem"
)
if
err
=
ioutil
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
if
err
=
os
.
WriteFile
(
path
,
[]
byte
(
data
),
0644
);
err
!=
nil
{
return
""
,
nil
,
err
return
""
,
nil
,
err
}
}
...
...
test/auto_test.go
View file @
5191959b
package
test
package
test
import
(
import
(
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"testing"
"testing"
...
@@ -12,7 +11,7 @@ import (
...
@@ -12,7 +11,7 @@ import (
func
TestAuto
(
t
*
testing
.
T
)
{
func
TestAuto
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
tmpdir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"coredns"
)
tmpdir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"coredns"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -42,7 +41,7 @@ func TestAuto(t *testing.T) {
...
@@ -42,7 +41,7 @@ func TestAuto(t *testing.T) {
}
}
// Write db.example.org to get example.org.
// 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
)
t
.
Fatal
(
err
)
}
}
...
@@ -71,7 +70,7 @@ func TestAuto(t *testing.T) {
...
@@ -71,7 +70,7 @@ func TestAuto(t *testing.T) {
func
TestAutoNonExistentZone
(
t
*
testing
.
T
)
{
func
TestAutoNonExistentZone
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
tmpdir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"coredns"
)
tmpdir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"coredns"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -110,7 +109,7 @@ func TestAutoNonExistentZone(t *testing.T) {
...
@@ -110,7 +109,7 @@ func TestAutoNonExistentZone(t *testing.T) {
func
TestAutoAXFR
(
t
*
testing
.
T
)
{
func
TestAutoAXFR
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Parallel
()
tmpdir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"coredns"
)
tmpdir
,
err
:=
os
.
MkdirTemp
(
os
.
TempDir
(),
"coredns"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -138,7 +137,7 @@ func TestAutoAXFR(t *testing.T) {
...
@@ -138,7 +137,7 @@ func TestAutoAXFR(t *testing.T) {
defer
i
.
Stop
()
defer
i
.
Stop
()
// Write db.example.org to get example.org.
// 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
)
t
.
Fatal
(
err
)
}
}
...
...
test/erratic_autopath_test.go
View file @
5191959b
package
test
package
test
import
(
import
(
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"testing"
"testing"
...
@@ -10,7 +9,7 @@ import (
...
@@ -10,7 +9,7 @@ import (
)
)
func
setupProxyTargetCoreDNS
(
t
*
testing
.
T
,
fn
func
(
string
))
{
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
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -24,7 +23,7 @@ google.com. IN A 172.217.25.110
...
@@ -24,7 +23,7 @@ google.com. IN A 172.217.25.110
`
`
path
:=
filepath
.
Join
(
tmpdir
,
"file"
)
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
)
t
.
Fatalf
(
"Could not write to temp file: %s"
,
err
)
}
}
defer
os
.
Remove
(
path
)
defer
os
.
Remove
(
path
)
...
...
test/file_reload_test.go
View file @
5191959b
package
test
package
test
import
(
import
(
"
io/ioutil
"
"
os
"
"testing"
"testing"
"time"
"time"
...
@@ -45,7 +45,7 @@ func TestZoneReload(t *testing.T) {
...
@@ -45,7 +45,7 @@ func TestZoneReload(t *testing.T) {
}
}
// Remove RR from the Apex
// 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
time
.
Sleep
(
20
*
time
.
Millisecond
)
// reload time, with some race insurance
...
...
test/metrics_test.go
View file @
5191959b
package
test
package
test
import
(
import
(
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -69,7 +68,7 @@ func TestMetricsRefused(t *testing.T) {
...
@@ -69,7 +68,7 @@ func TestMetricsRefused(t *testing.T) {
}
}
func
TestMetricsAuto
(
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
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -95,7 +94,7 @@ func TestMetricsAuto(t *testing.T) {
...
@@ -95,7 +94,7 @@ func TestMetricsAuto(t *testing.T) {
defer
i
.
Stop
()
defer
i
.
Stop
()
// Write db.example.org to get example.org.
// 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
)
t
.
Fatal
(
err
)
}
}
time
.
Sleep
(
110
*
time
.
Millisecond
)
// wait for it to be picked up
time
.
Sleep
(
110
*
time
.
Millisecond
)
// wait for it to be picked up
...
...
test/plugin_dnssec_test.go
View file @
5191959b
package
test
package
test
import
(
import
(
"io/ioutil"
"os"
"os"
"testing"
"testing"
...
@@ -56,10 +55,10 @@ func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
...
@@ -56,10 +55,10 @@ func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
}
}
func
createKeyFile
(
t
*
testing
.
T
)
func
()
{
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==`
),
[]
byte
(
`example.org. IN DNSKEY 256 3 13 tDyI0uEIDO4SjhTJh1AVTFBLpKhY3He5BdAlKztewiZ7GecWj94DOodg ovpN73+oJs+UfZ+p9zOSN5usGAlHrw==`
),
0644
)
0644
)
ioutil
.
WriteFile
(
base
+
".private"
,
os
.
WriteFile
(
base
+
".private"
,
[]
byte
(
`Private-key-format: v1.3
[]
byte
(
`Private-key-format: v1.3
Algorithm: 13 (ECDSAP256SHA256)
Algorithm: 13 (ECDSAP256SHA256)
PrivateKey: HPmldSNfrkj/aDdUMFwuk/lgzaC5KIsVEG3uoYvF4pQ=
PrivateKey: HPmldSNfrkj/aDdUMFwuk/lgzaC5KIsVEG3uoYvF4pQ=
...
...
test/readme_test.go
View file @
5191959b
...
@@ -3,7 +3,6 @@ package test
...
@@ -3,7 +3,6 @@ package test
import
(
import
(
"bufio"
"bufio"
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
...
@@ -52,7 +51,7 @@ func TestReadme(t *testing.T) {
...
@@ -52,7 +51,7 @@ func TestReadme(t *testing.T) {
defer
remove
(
contents
)
defer
remove
(
contents
)
middle
:=
filepath
.
Join
(
".."
,
"plugin"
)
middle
:=
filepath
.
Join
(
".."
,
"plugin"
)
dirs
,
err
:=
ioutil
.
ReadDir
(
middle
)
dirs
,
err
:=
os
.
ReadDir
(
middle
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Could not read %s: %q"
,
middle
,
err
)
t
.
Fatalf
(
"Could not read %s: %q"
,
middle
,
err
)
}
}
...
@@ -173,7 +172,7 @@ func sectionsFromReadme(readme string) error {
...
@@ -173,7 +172,7 @@ func sectionsFromReadme(readme string) error {
func
create
(
c
map
[
string
]
string
)
{
func
create
(
c
map
[
string
]
string
)
{
for
name
,
content
:=
range
c
{
for
name
,
content
:=
range
c
{
ioutil
.
WriteFile
(
name
,
[]
byte
(
content
),
0644
)
os
.
WriteFile
(
name
,
[]
byte
(
content
),
0644
)
}
}
}
}
...
...
test/reload_test.go
View file @
5191959b
...
@@ -3,7 +3,7 @@ package test
...
@@ -3,7 +3,7 @@ package test
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"io
/ioutil
"
"io"
"net/http"
"net/http"
"strings"
"strings"
"testing"
"testing"
...
@@ -105,7 +105,7 @@ func TestReloadMetricsHealth(t *testing.T) {
...
@@ -105,7 +105,7 @@ func TestReloadMetricsHealth(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
ok
,
_
:=
io
util
.
ReadAll
(
resp
.
Body
)
ok
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
resp
.
Body
.
Close
()
resp
.
Body
.
Close
()
if
string
(
ok
)
!=
http
.
StatusText
(
http
.
StatusOK
)
{
if
string
(
ok
)
!=
http
.
StatusText
(
http
.
StatusOK
)
{
t
.
Errorf
(
"Failed to receive OK, got %s"
,
ok
)
t
.
Errorf
(
"Failed to receive OK, got %s"
,
ok
)
...
@@ -117,7 +117,7 @@ func TestReloadMetricsHealth(t *testing.T) {
...
@@ -117,7 +117,7 @@ func TestReloadMetricsHealth(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
const
proc
=
"coredns_build_info"
const
proc
=
"coredns_build_info"
metrics
,
_
:=
io
util
.
ReadAll
(
resp
.
Body
)
metrics
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
if
!
bytes
.
Contains
(
metrics
,
[]
byte
(
proc
))
{
if
!
bytes
.
Contains
(
metrics
,
[]
byte
(
proc
))
{
t
.
Errorf
(
"Failed to see %s in metric output"
,
proc
)
t
.
Errorf
(
"Failed to see %s in metric output"
,
proc
)
}
}
...
@@ -129,7 +129,7 @@ func collectMetricsInfo(addr string, procs ...string) error {
...
@@ -129,7 +129,7 @@ func collectMetricsInfo(addr string, procs ...string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
metrics
,
_
:=
io
util
.
ReadAll
(
resp
.
Body
)
metrics
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
for
_
,
p
:=
range
procs
{
for
_
,
p
:=
range
procs
{
if
!
bytes
.
Contains
(
metrics
,
[]
byte
(
p
))
{
if
!
bytes
.
Contains
(
metrics
,
[]
byte
(
p
))
{
return
fmt
.
Errorf
(
"failed to see %s in metric output
\n
%s"
,
p
,
metrics
)
return
fmt
.
Errorf
(
"failed to see %s in metric output
\n
%s"
,
p
,
metrics
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment