Use mock syslog in test suites (except core and log). Drop SwitchLog().

This commit is contained in:
Tom Clegg 2015-07-21 17:06:39 -04:00
parent bf0142897e
commit 2d0be62966
7 changed files with 16 additions and 25 deletions

View File

@ -332,6 +332,8 @@ var BadAlgorithmCSRhex = "308202aa30820192020100300d310b300906035504061302" +
var FarFuture = time.Date(2100, 1, 1, 0, 0, 0, 0, time.UTC)
var FarPast = time.Date(1950, 1, 1, 0, 0, 0, 0, time.UTC)
var log = mocks.UseMockLog()
// CFSSL config
const profileName = "ee"
const caKeyFile = "../test/test-ca.key"

View File

@ -45,23 +45,6 @@ func (lm *LogMessage) String() string {
return levelName[lm.Priority&7] + ": " + lm.Message
}
// SwitchLog changes the SyslogWriter used by the current singleton
// audit logger, and returns the previous value. Example:
//
// func TestFoo(t *testing.T) {
// log := mocks.NewSyslogWriter()
// defer log.Close()
// defer mocks.SwitchLog(mocks.SwitchLog(log))
// // ...
// Assert(t, len(log.GetAll()) > 0, "Should have logged something")
// }
func SwitchLog(sw blog.SyslogWriter) blog.SyslogWriter {
al := blog.GetAuditLogger()
was := al.SyslogWriter
al.SyslogWriter = sw
return was
}
// UseMockLog changes the SyslogWriter used by the current singleton
// audit logger to a new mock logger, and returns the mock. Example:
//

View File

@ -9,8 +9,11 @@ import (
"testing"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/mocks"
)
var log = mocks.UseMockLog()
func TestWillingToIssue(t *testing.T) {
shouldBeSyntaxError := []string{
``, // Empty name

View File

@ -132,6 +132,8 @@ var (
}
AuthzUpdated = core.Authorization{}
AuthzFinal = core.Authorization{}
log = mocks.UseMockLog()
)
func initAuthorities(t *testing.T) (core.CertificateAuthority, *DummyValidationAuthority, *sa.SQLStorageAuthority, core.RegistrationAuthority) {

View File

@ -13,9 +13,12 @@ import (
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/mocks"
"github.com/letsencrypt/boulder/test"
)
var log = mocks.UseMockLog()
const JWK1JSON = `{
"kty": "RSA",
"n": "vuc785P8lBj3fUxyZchF_uZw6WtbxcorqgTyq-qapF5lrO1U82Tp93rpXlmctj6fyFHBVVB5aXnUHJ7LZeVPod7Wnfl8p5OyhlHQHC8BnzdzCqCMKmWZNX5DtETDId0qzU7dPzh0LP0idt5buU7L9QNaabChw3nnaL47iu_1Di5Wp264p2TwACeedv2hfRDjDlJmaQXuS8Rtv9GnRWyC9JBu7XmGvGDziumnJH7Hyzh3VNu-kSPQD3vuAFgMZS6uUzOztCkT0fpOalZI6hqxtWLvXUMj-crXrn-Maavz8qRhpAyp5kcYk3jiHGgQIi7QSK2JIdRJ8APyX9HlmTN5AQ",

View File

@ -18,11 +18,14 @@ import (
_ "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/mattn/go-sqlite3"
jose "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/square/go-jose"
"github.com/letsencrypt/boulder/core"
"github.com/letsencrypt/boulder/mocks"
"github.com/letsencrypt/boulder/test"
"io/ioutil"
"testing"
)
var log = mocks.UseMockLog()
func initSA(t *testing.T) *SQLStorageAuthority {
sa, err := NewSQLStorageAuthority("sqlite3", ":memory:")
if err != nil {

View File

@ -52,6 +52,8 @@ var TheKey = rsa.PrivateKey{
var ident = core.AcmeIdentifier{Type: core.IdentifierDNS, Value: "localhost"}
var log = mocks.UseMockLog()
const expectedToken = "THETOKEN"
const pathWrongToken = "wrongtoken"
const path404 = "404"
@ -203,10 +205,6 @@ func TestSimpleHttpTLS(t *testing.T) {
va := NewValidationAuthorityImpl(true)
va.DNSResolver = &mocks.MockDNS{}
log := mocks.NewSyslogWriter()
defer log.Close()
defer mocks.SwitchLog(mocks.SwitchLog(log))
chall := core.Challenge{Path: "test", Token: expectedToken}
stopChan := make(chan bool, 1)
@ -215,6 +213,7 @@ func TestSimpleHttpTLS(t *testing.T) {
defer func() { stopChan <- true }()
<-waitChan
log.Clear()
finChall, err := va.validateSimpleHTTP(ident, chall)
test.AssertEquals(t, finChall.Status, core.StatusValid)
test.AssertNotError(t, err, chall.Path)
@ -227,10 +226,6 @@ func TestSimpleHttp(t *testing.T) {
va := NewValidationAuthorityImpl(true)
va.DNSResolver = &mocks.MockDNS{}
log := mocks.NewSyslogWriter()
defer log.Close()
defer mocks.SwitchLog(mocks.SwitchLog(log))
tls := false
chall := core.Challenge{Path: "test", Token: expectedToken, TLS: &tls}