Move logging, updating and testing utils into common directory

This commit is contained in:
Bryan Boreham committed 2015-01-02 14:49:49 +00:00
1 parent 5da2219dc8
commit 82b54aabcd
8 files changed
+69 -52

No files matched your search

+1
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/miekg/dns"
. "github.com/zettio/weave/common"
"io"
"log"
"net"
-37
View File
@@ -1,37 +0,0 @@
package nameserver
import (
"io"
"io/ioutil"
"log"
"os"
)
const (
standardLogFlags = log.Ldate | log.Ltime | log.Lmicroseconds
)
// Largely taken from
// http://www.goinggo.net/2013/11/using-log-package-in-go.html
var (
Debug *log.Logger
Info *log.Logger
Warning *log.Logger
Error *log.Logger
)
func InitLogging(debugHandle io.Writer,
infoHandle io.Writer,
warningHandle io.Writer,
errorHandle io.Writer) {
Debug = log.New(debugHandle, "DEBUG: ", standardLogFlags)
Info = log.New(infoHandle, "INFO: ", standardLogFlags)
Warning = log.New(warningHandle, "WARNING: ", standardLogFlags)
Error = log.New(errorHandle, "ERROR: ", standardLogFlags)
}
func init() {
InitLogging(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
}
+1
View File
@@ -2,6 +2,7 @@ package nameserver
import (
"github.com/miekg/dns"
. "github.com/zettio/weave/common"
"net"
)
+1
View File
@@ -3,6 +3,7 @@ package nameserver
import (
"fmt"
"github.com/miekg/dns"
. "github.com/zettio/weave/common"
"net"
)
-38
View File
@@ -1,38 +0,0 @@
package nameserver
import (
"reflect"
"testing"
)
func assertNoErr(t *testing.T, err error) {
if err != nil {
t.Fatal(err)
}
}
func assertStatus(t *testing.T, got int, wanted int, desc string) {
if got != wanted {
t.Fatalf("Expected %s %d but got %d", desc, wanted, got)
}
}
func assertErrorInterface(t *testing.T, got interface{}, wanted interface{}, desc string) {
if got == nil {
t.Fatalf("Expected %s but got nil (%s)", reflect.TypeOf(wanted).Elem(), desc)
}
gotT, wantedT := reflect.TypeOf(got), reflect.TypeOf(wanted).Elem()
if !gotT.Implements(wantedT) {
t.Fatalf("Expected %s but got %s (%s)", wantedT, gotT, desc)
}
}
func assertErrorType(t *testing.T, got interface{}, wanted interface{}, desc string) {
if got == nil {
t.Fatalf("Expected %s but got nil (%s)", reflect.TypeOf(wanted).Elem(), desc)
}
gotT, wantedT := reflect.TypeOf(got), reflect.TypeOf(wanted).Elem()
if gotT != wantedT {
t.Fatalf("Expected %s but got %s (%s)", wantedT, gotT, desc)
}
}
+1
View File
@@ -2,6 +2,7 @@ package nameserver
import (
"github.com/fsouza/go-dockerclient"
. "github.com/zettio/weave/common"
)
func checkError(err error, apiPath string) {