coredns/test/reload_test.go
Yong Tang 102cfbd7fe Use gometalinter and enforcing go fmt/lint/vet (#1108)
* Use gometalinter and enforcing go fmt/lint/vet

Before this PR go fmt is enabled, go lint is suggest only.
From time to time we have to manually check for go lint and go vet
for any issues.

This fix uses gometalinter and enforcing go fmt/lint/vet.
Several reasons:
- gometalinter could handle multiple linters concurrently
- gometalinter supports suppression with `// nolint[: <linter>]`

Previously one reason we didn't enable go lint was due to the
```
warning: context.Context should be the first parameter of a function (golint)
```
this is now possible with gometalinter and `// nolint: golint` (See changes).

This fix also discovered several go vet issues and fixes it.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Fix several issues reported by gometalinter (go vet)

This commit fixes several issues reported by gometalinter (go vet).

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Increase deadline

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2017-09-24 11:59:04 +01:00

54 lines
966 B
Go

package test
import (
"testing"
"github.com/miekg/dns"
)
func TestReload(t *testing.T) {
corefile := `.:0 {
whoami
}
`
coreInput := NewInput(corefile)
c, err := CoreDNSServer(corefile)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
udp, _ := CoreDNSServerPorts(c, 0)
send(t, udp)
c1, err := c.Restart(coreInput)
if err != nil {
t.Fatal(err)
}
udp, _ = CoreDNSServerPorts(c1, 0)
send(t, udp)
c1.Stop()
}
func send(t *testing.T, server string) {
m := new(dns.Msg)
m.SetQuestion("whoami.example.org.", dns.TypeSRV)
r, err := dns.Exchange(m, server)
if err != nil {
// This seems to fail a lot on travis, quick'n dirty: redo
r, err = dns.Exchange(m, server)
if err != nil {
return
}
}
if r.Rcode != dns.RcodeSuccess {
t.Fatalf("Expected successful reply, got %s", dns.RcodeToString[r.Rcode])
}
if len(r.Extra) != 2 {
t.Fatalf("Expected 2 RRs in additional, got %d", len(r.Extra))
}
}