Add TestServer (#102)

Add a fullblown testing server. This allows us to do integration tests.

Also add a basic proxy test. Further tests will test etcd proxy
and stub zone communication and other "wildish" configurations.
Redo the server startup, so we can access the ports it listens on when
it has started up (with dns.ActivateAndServer).

Extend the .travis file to download etcd and test for that as well.

Put integration tests in test dir
This commit is contained in:
Miek Gieben
2016-04-10 18:50:11 +01:00
parent db98cd4e4b
commit 0ea2a6088d
13 changed files with 191 additions and 135 deletions

View File

@@ -26,6 +26,7 @@ import (
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/miekg/coredns/core/https"
@@ -236,6 +237,7 @@ func startServers(groupings bindingGroup) error {
// start the server
// TODO(miek): for now will always be nil, so we will run ListenAndServe()
// TODO(miek): this is also why graceful restarts don't work.
if ln != nil {
//errChan <- s.Serve(ln)
} else {
@@ -386,3 +388,24 @@ type Input interface {
// that could be loaded again later if requested.
IsFile() bool
}
// TestServer returns a test server.
// The port can be retreived with ... . The testserver itself can be stopped
// with Stop(). It just takes a normal Corefile input, but doesn't use the port.
func TestServer(t *testing.T, corefile string) (*server.Server, error) {
cdyfile := CaddyfileInput{Contents: []byte(corefile)}
configs, err := loadConfigs(path.Base(cdyfile.Path()), bytes.NewReader(cdyfile.Body()))
if err != nil {
return nil, err
}
groupings, err := arrangeBindings(configs)
if err != nil {
return nil, err
}
t.Logf("Starting %d servers", len(groupings))
group := groupings[0]
s, err := server.New(group.BindAddr.String(), group.Configs, time.Second)
return s, err
}