aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-10-01 07:41:29 +0100
committerGravatar GitHub <noreply@github.com> 2019-10-01 07:41:29 +0100
commitdbd1c047cb973fc669fbe4e97dc12e7b3d3e6ed8 (patch)
tree4737fb65ef07bdfd3e24e2c76a147edde5db852c /test
parent55a01dadaacc33674aff1e936b101695f9de32cf (diff)
downloadcoredns-dbd1c047cb973fc669fbe4e97dc12e7b3d3e6ed8.tar.gz
coredns-dbd1c047cb973fc669fbe4e97dc12e7b3d3e6ed8.tar.zst
coredns-dbd1c047cb973fc669fbe4e97dc12e7b3d3e6ed8.zip
Run gostaticheck (#3325)
* Run gostaticheck Run gostaticcheck on the codebase and fix almost all flagged items. Only keep * coremain/run.go:192:2: var appVersion is unused (U1000) * plugin/chaos/setup.go:54:3: the surrounding loop is unconditionally terminated (SA4004) * plugin/etcd/setup.go:103:3: the surrounding loop is unconditionally terminated (SA4004) * plugin/pkg/replacer/replacer.go:274:13: argument should be pointer-like to avoid allocations (SA6002) * plugin/route53/setup.go:124:28: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made. (SA1019) * test/grpc_test.go:25:69: grpc.WithTimeout is deprecated: use DialContext and context.WithTimeout instead. Will be supported throughout 1.x. (SA1019) The first one isn't true, as this is set via ldflags. The rest is minor. The deprecation should be fixed at some point; I'll file some issues. Signed-off-by: Miek Gieben <miek@miek.nl> * Make sure to plug in the plugins import the plugins, that file that did this was removed, put it in the reload test as this requires an almost complete coredns server. Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'test')
-rw-r--r--test/doc.go2
-rw-r--r--test/external_test.go72
-rw-r--r--test/plugin_test.go43
-rw-r--r--test/server.go3
4 files changed, 3 insertions, 117 deletions
diff --git a/test/doc.go b/test/doc.go
index ba09e8772..528092a85 100644
--- a/test/doc.go
+++ b/test/doc.go
@@ -1,2 +1,2 @@
-// Package test contains function and types useful for writing tests
+// Package test contains function and types useful for writing tests.
package test
diff --git a/test/external_test.go b/test/external_test.go
deleted file mode 100644
index 8e6adab91..000000000
--- a/test/external_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package test
-
-import (
- "fmt"
- "os"
- "os/exec"
- "strings"
- "testing"
-)
-
-// Go get external example plugin, compile it into CoreDNS
-// and check if it is really there, but running coredns -plugins.
-
-// Dangerous test as it messes with your git tree, maybe use tag?
-func testExternalPluginCompile(t *testing.T) {
- if err := addExamplePlugin(); err != nil {
- t.Fatal(err)
- }
- defer run(t, gitReset)
-
- if _, err := run(t, goGet); err != nil {
- t.Fatal(err)
- }
-
- if _, err := run(t, goGen); err != nil {
- t.Fatal(err)
- }
-
- if _, err := run(t, goBuild); err != nil {
- t.Fatal(err)
- }
-
- out, err := run(t, coredns)
- if err != nil {
- t.Fatal(err)
- }
-
- if !strings.Contains(string(out), "dns.example") {
- t.Fatal("Plugin dns.example should be there")
- }
-}
-
-func run(t *testing.T, c *exec.Cmd) ([]byte, error) {
- c.Dir = ".."
- out, err := c.Output()
- if err != nil {
- return nil, fmt.Errorf("run: failed to run %s %s: %q", c.Args[0], c.Args[1], err)
- }
- return out, nil
-
-}
-
-func addExamplePlugin() error {
- f, err := os.OpenFile("../plugin.cfg", os.O_APPEND|os.O_WRONLY, os.ModeAppend)
- if err != nil {
- return err
- }
- defer f.Close()
-
- _, err = f.WriteString(example)
- return err
-}
-
-var (
- goBuild = exec.Command("go", "build")
- goGen = exec.Command("go", "generate")
- goGet = exec.Command("go", "get", "github.com/coredns/example")
- gitReset = exec.Command("git", "checkout", "core/*")
- coredns = exec.Command("./coredns", "-plugins")
-)
-
-const example = "1001:example:github.com/coredns/example"
diff --git a/test/plugin_test.go b/test/plugin_test.go
deleted file mode 100644
index 4003a958f..000000000
--- a/test/plugin_test.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package test
-
-import (
- "testing"
-
- "github.com/coredns/coredns/plugin/test"
-
- "github.com/miekg/dns"
-
- // Load all managed plugins in github.com/coredns/coredns
- _ "github.com/coredns/coredns/core/plugin"
-)
-
-func benchmarkLookupBalanceRewriteCache(b *testing.B) {
- t := new(testing.T)
- name, rm, err := test.TempFile(".", exampleOrg)
- if err != nil {
- t.Fatalf("Failed to create zone: %s", err)
- }
- defer rm()
-
- corefile := `example.org:0 {
- file ` + name + `
- rewrite type ANY HINFO
- loadbalance
-}
-`
-
- ex, udp, _, err := CoreDNSServerAndPorts(corefile)
- if err != nil {
- t.Fatalf("Could not get CoreDNS serving instance: %s", err)
- }
- defer ex.Stop()
-
- c := new(dns.Client)
- m := new(dns.Msg)
- m.SetQuestion("example.org.", dns.TypeA)
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- c.Exchange(m, udp)
- }
-}
diff --git a/test/server.go b/test/server.go
index 93016501d..9908285d1 100644
--- a/test/server.go
+++ b/test/server.go
@@ -4,9 +4,10 @@ import (
"sync"
"github.com/coredns/coredns/core/dnsserver"
-
// Hook in CoreDNS.
_ "github.com/coredns/coredns/core"
+ // Load all managed plugins in github.com/coredns/coredns
+ _ "github.com/coredns/coredns/core/plugin"
"github.com/caddyserver/caddy"
)