aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-10-31 07:14:49 +0000
committerGravatar GitHub <noreply@github.com> 2017-10-31 07:14:49 +0000
commit87c9f00c83212734d7ab0172ac34aee5bd271b07 (patch)
treecf100e27d2d91259a7e389900133e4a154c393e5 /test
parent4a4556f0d6a36508c144d1021950972f9b9ff675 (diff)
downloadcoredns-87c9f00c83212734d7ab0172ac34aee5bd271b07.tar.gz
coredns-87c9f00c83212734d7ab0172ac34aee5bd271b07.tar.zst
coredns-87c9f00c83212734d7ab0172ac34aee5bd271b07.zip
readme: more tests (#1184)
* readme: more tests Add dnssec and file plugin to the test readme. This requires creating a bunch of files with the right content. Doing so already unconvered an unconditional type assertion in DNSSEC. This PR will include the fix for that as well. Also extended the snippets in the file plugin README, so that they are whole Corefile - showing more value and checking all corefile snippets. Create outliner right now is the kubernetes plugin, because even setting the right env vars will result in: open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory": Which we can't create for a test. * lint
Diffstat (limited to 'test')
-rw-r--r--test/readme_test.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/readme_test.go b/test/readme_test.go
index dcbb56619..f8ae0e346 100644
--- a/test/readme_test.go
+++ b/test/readme_test.go
@@ -14,7 +14,25 @@ import (
"github.com/mholt/caddy"
)
-// TestReadme parses all README.md's of the plugins and checks if every example Corefile
+// As we use the filesystem as-is, these files need to exist ON DISK for the readme test to work. This is especially
+// useful for the *file* and *dnssec* plugins as their Corefiles are now tested as well. We create files in the
+// current dir for all these, meaning the example READMEs MUST use relative path in their READMEs.
+var contents = map[string]string{
+ "Kexample.org.+013+45330.key": examplePub,
+ "Kexample.org.+013+45330.private": examplePriv,
+ "example.org.signed": exampleOrg, // not signed, but does not matter for this test.
+}
+
+const (
+ examplePub = `example.org. IN DNSKEY 256 3 13 eNMYFZYb6e0oJOV47IPo5f/UHy7wY9aBebotvcKakIYLyyGscBmXJQhbKLt/LhrMNDE2Q96hQnI5PdTBeOLzhQ==
+`
+ examplePriv = `Private-key-format: v1.3
+Algorithm: 13 (ECDSAP256SHA256)
+PrivateKey: f03VplaIEA+KHI9uizlemUSbUJH86hPBPjmcUninPoM=
+`
+)
+
+// TestReadme parses all README.mds of the plugins and checks if every example Corefile
// actually works. Each corefile snippet is only used if the language is set to 'corefile':
//
// ~~~ corefile
@@ -27,6 +45,9 @@ func TestReadme(t *testing.T) {
caddy.Quiet = true
dnsserver.Quiet = true
+ create(contents)
+ defer remove(contents)
+
log.SetOutput(ioutil.Discard)
middle := filepath.Join("..", "plugin")
@@ -99,3 +120,15 @@ func corefileFromReadme(readme string) ([]*Input, error) {
}
return input, nil
}
+
+func create(c map[string]string) {
+ for name, content := range c {
+ ioutil.WriteFile(name, []byte(content), 0644)
+ }
+}
+
+func remove(c map[string]string) {
+ for name := range c {
+ os.Remove(name)
+ }
+}