fix tests
This commit is contained in:
parent
b786920c03
commit
5fb6741052
|
|
@ -9,13 +9,15 @@ import (
|
|||
"log/syslog"
|
||||
"testing"
|
||||
|
||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
|
||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/streadway/amqp"
|
||||
"github.com/letsencrypt/boulder/log"
|
||||
)
|
||||
|
||||
func TestNewLoggingAnalysisEngine(t *testing.T) {
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
writer, _ := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
log, _ := log.NewAuditLogger(writer)
|
||||
log, _ := log.NewAuditLogger(writer, stats)
|
||||
ae := NewLoggingAnalysisEngine(log)
|
||||
|
||||
// Trivially check an empty mock message
|
||||
|
|
@ -43,8 +45,9 @@ func (m *MockAck) Reject(tag uint64, requeue bool) error {
|
|||
}
|
||||
|
||||
func TestAnalysisEngineBadMessage(t *testing.T) {
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
writer, _ := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
log, _ := log.NewAuditLogger(writer)
|
||||
log, _ := log.NewAuditLogger(writer, stats)
|
||||
ae := NewLoggingAnalysisEngine(log)
|
||||
|
||||
// Trivially check an empty mock message
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const auditTag = "[AUDIT]"
|
|||
// to send a message as an audit event.
|
||||
type AuditLogger struct {
|
||||
*syslog.Writer
|
||||
stats statsd.Statter
|
||||
Stats statsd.Statter
|
||||
}
|
||||
|
||||
// Dial establishes a connection to the log daemon by passing through
|
||||
|
|
@ -52,7 +52,7 @@ func (log *AuditLogger) Audit(msg string) (err error) {
|
|||
fmt.Println(msg)
|
||||
err = log.Notice(fmt.Sprintf("%s %s", auditTag, msg))
|
||||
|
||||
log.stats.Inc("Logging.Audit", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Audit", 1, 1.0)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func (log *AuditLogger) AuditErr(msg error) (err error) {
|
|||
fmt.Println(msg)
|
||||
err = log.Err(fmt.Sprintf("%s %s", auditTag, msg))
|
||||
|
||||
log.stats.Inc("Logging.Audit", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Audit", 1, 1.0)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -77,42 +77,42 @@ func (log *AuditLogger) WarningErr(msg error) (err error) {
|
|||
|
||||
func (log *AuditLogger) Alert(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Alert", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Alert", 1, 1.0)
|
||||
return log.Writer.Alert(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Crit(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Crit", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Crit", 1, 1.0)
|
||||
return log.Writer.Crit(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Debug(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Debug", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Debug", 1, 1.0)
|
||||
return log.Writer.Debug(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Emerg(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Emerg", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Emerg", 1, 1.0)
|
||||
return log.Writer.Emerg(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Err(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Err", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Err", 1, 1.0)
|
||||
return log.Writer.Err(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Info(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Info", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Info", 1, 1.0)
|
||||
return log.Writer.Info(msg)
|
||||
}
|
||||
|
||||
func (log *AuditLogger) Warning(msg string) (err error) {
|
||||
fmt.Println(msg)
|
||||
log.stats.Inc("Logging.Warning", 1, 1.0)
|
||||
log.Stats.Inc("Logging.Warning", 1, 1.0)
|
||||
return log.Writer.Warning(msg)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,29 +10,35 @@ import (
|
|||
"log/syslog"
|
||||
"testing"
|
||||
|
||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
|
||||
"github.com/letsencrypt/boulder/test"
|
||||
)
|
||||
|
||||
|
||||
func TestConstruction(t *testing.T) {
|
||||
writer, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
test.AssertNotError(t, err, "Could not construct syslog object")
|
||||
|
||||
_, err = NewAuditLogger(writer)
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
_, err = NewAuditLogger(writer, stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
}
|
||||
|
||||
func TestDial(t *testing.T) {
|
||||
_, err := Dial("", "", "tag")
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
_, err := Dial("", "", "tag", stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
}
|
||||
|
||||
func TestDialError(t *testing.T) {
|
||||
_, err := Dial("_fail", "_fail", "tag")
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
_, err := Dial("_fail", "_fail", "tag", stats)
|
||||
test.AssertError(t, err, "Audit Logger should have failed")
|
||||
}
|
||||
|
||||
func TestConstructionNil(t *testing.T) {
|
||||
_, err := NewAuditLogger(nil)
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
_, err := NewAuditLogger(nil, stats)
|
||||
test.AssertError(t, err, "Nil shouldn't be permitted.")
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +46,8 @@ func TestEmit(t *testing.T) {
|
|||
writer, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
test.AssertNotError(t, err, "Could not construct syslog object")
|
||||
|
||||
audit, err := NewAuditLogger(writer)
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
audit, err := NewAuditLogger(writer, stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
|
||||
audit.Audit("test message")
|
||||
|
|
@ -50,14 +57,16 @@ func TestEmitEmpty(t *testing.T) {
|
|||
writer, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
test.AssertNotError(t, err, "Could not construct syslog object")
|
||||
|
||||
audit, err := NewAuditLogger(writer)
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
audit, err := NewAuditLogger(writer, stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
|
||||
audit.Audit("")
|
||||
}
|
||||
|
||||
func TestEmitErrors(t *testing.T) {
|
||||
audit, _ := Dial("", "", "tag")
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
audit, _ := Dial("", "", "tag", stats)
|
||||
|
||||
audit.AuditErr(errors.New("Error Audit"))
|
||||
audit.WarningErr(errors.New("Warning Audit"))
|
||||
|
|
@ -67,7 +76,8 @@ func TestSyslogMethods(t *testing.T) {
|
|||
writer, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "tag")
|
||||
test.AssertNotError(t, err, "Could not construct syslog object")
|
||||
|
||||
audit, err := NewAuditLogger(writer)
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
audit, err := NewAuditLogger(writer, stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
|
||||
audit.Audit("audit-logger_test.go: audit-notice")
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import (
|
|||
"strings"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
|
||||
"github.com/letsencrypt/boulder/ra"
|
||||
blog "github.com/letsencrypt/boulder/log"
|
||||
"github.com/letsencrypt/boulder/test"
|
||||
|
|
@ -26,8 +28,9 @@ func makeBody(s string) (io.ReadCloser) {
|
|||
// - RA returns with a cert success
|
||||
// - RA returns with a failure
|
||||
func TestIssueCertificate(t *testing.T) {
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
syslogger, _ := syslog.New(syslog.LOG_DEBUG, "test")
|
||||
log := blog.AuditLogger{syslogger}
|
||||
log := blog.AuditLogger{syslogger, stats}
|
||||
// TODO: Use a mock RA so we can test various conditions of authorized, not authorized, etc.
|
||||
ra := ra.NewRegistrationAuthorityImpl(&log)
|
||||
wfe := NewWebFrontEndImpl(&log)
|
||||
|
|
|
|||
Loading…
Reference in New Issue