Use a test logger

This commit is contained in:
Brian Picciano 2024-10-23 20:38:39 +02:00
parent bbae88ab4b
commit 63cefd403e
4 changed files with 13 additions and 12 deletions

View File

@ -70,13 +70,10 @@ type divider interface {
Divide2FromMeta(ctx context.Context) (int, error) Divide2FromMeta(ctx context.Context) (int, error)
} }
var testHandler = func() Handler { func testHandler(t *testing.T) Handler {
var ( var (
logger = mlog.NewLogger(&mlog.LoggerOpts{ logger = mlog.NewTestLogger(t)
MaxLevel: mlog.LevelDebug.Int(), d = divider(dividerImpl{})
})
d = divider(dividerImpl{})
) )
return Chain( return Chain(
@ -85,7 +82,7 @@ var testHandler = func() Handler {
)( )(
NewDispatchHandler(&d), NewDispatchHandler(&d),
) )
}() }
func testClient(t *testing.T, client Client) { func testClient(t *testing.T, client Client) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@ -194,7 +191,7 @@ func TestReadWriter(t *testing.T) {
clientRW = rw{clientReader, clientWriter} clientRW = rw{clientReader, clientWriter}
handlerRW = rw{handlerReader, handlerWriter} handlerRW = rw{handlerReader, handlerWriter}
server = NewReadWriterServer(testHandler, handlerRW) server = NewReadWriterServer(testHandler(t), handlerRW)
client = NewReadWriterClient(clientRW) client = NewReadWriterClient(clientRW)
wg = new(sync.WaitGroup) wg = new(sync.WaitGroup)
@ -220,7 +217,7 @@ func TestReadWriter(t *testing.T) {
} }
func TestHTTP(t *testing.T) { func TestHTTP(t *testing.T) {
server := httptest.NewServer(NewHTTPHandler(testHandler)) server := httptest.NewServer(NewHTTPHandler(testHandler(t)))
t.Cleanup(server.Close) t.Cleanup(server.Close)
testClient(t, NewHTTPClient(server.URL)) testClient(t, NewHTTPClient(server.URL))
} }
@ -228,7 +225,7 @@ func TestHTTP(t *testing.T) {
func TestUnixHTTP(t *testing.T) { func TestUnixHTTP(t *testing.T) {
var ( var (
unixSocketPath = filepath.Join(t.TempDir(), "test.sock") unixSocketPath = filepath.Join(t.TempDir(), "test.sock")
server = httptest.NewUnstartedServer(NewHTTPHandler(testHandler)) server = httptest.NewUnstartedServer(NewHTTPHandler(testHandler(t)))
) )
var err error var err error

View File

@ -102,7 +102,7 @@ func newIntegrationHarness(t *testing.T) *integrationHarness {
return &integrationHarness{ return &integrationHarness{
ctx: context.Background(), ctx: context.Background(),
logger: mlog.NewLogger(nil), logger: mlog.NewTestLogger(t),
rootDir: toolkit.Dir{Path: rootDir}, rootDir: toolkit.Dir{Path: rootDir},
} }
} }

View File

@ -4,7 +4,7 @@ go 1.22
require ( require (
code.betamike.com/micropelago/pmux v0.0.0-20240719134913-f5fce902e8c4 code.betamike.com/micropelago/pmux v0.0.0-20240719134913-f5fce902e8c4
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7 dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20241023182613-55984cdf5233
github.com/adrg/xdg v0.4.0 github.com/adrg/xdg v0.4.0
github.com/jxskiss/base62 v1.1.0 github.com/jxskiss/base62 v1.1.0
github.com/minio/minio-go/v7 v7.0.28 github.com/minio/minio-go/v7 v7.0.28

View File

@ -2,6 +2,10 @@ code.betamike.com/micropelago/pmux v0.0.0-20240719134913-f5fce902e8c4 h1:n4pGP12
code.betamike.com/micropelago/pmux v0.0.0-20240719134913-f5fce902e8c4/go.mod h1:WlEWacLREVfIQl1IlBjKzuDgL56DFRvyl7YiL5gGP4w= code.betamike.com/micropelago/pmux v0.0.0-20240719134913-f5fce902e8c4/go.mod h1:WlEWacLREVfIQl1IlBjKzuDgL56DFRvyl7YiL5gGP4w=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7 h1:wKQ3bXzG+KQDtRAN/xaRZ4aQtJe1pccleG6V43MvFxw= dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7 h1:wKQ3bXzG+KQDtRAN/xaRZ4aQtJe1pccleG6V43MvFxw=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7/go.mod h1:nP+AtQWrc3k5qq5y3ABiBLkOfUPlk/FO9fpTFpF+jgs= dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20240511135822-4ab1176672d7/go.mod h1:nP+AtQWrc3k5qq5y3ABiBLkOfUPlk/FO9fpTFpF+jgs=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20241023133804-cedd67cf2652 h1:onyZbHYR1GJJOVd8iRtwVpgrowukWNl3EA0gWYRxixs=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20241023133804-cedd67cf2652/go.mod h1:nP+AtQWrc3k5qq5y3ABiBLkOfUPlk/FO9fpTFpF+jgs=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20241023182613-55984cdf5233 h1:Ea4HixNfDNDPh7zMngPpEeDf8gpociSPEROBFBedqIY=
dev.mediocregopher.com/mediocre-go-lib.git v0.0.0-20241023182613-55984cdf5233/go.mod h1:nP+AtQWrc3k5qq5y3ABiBLkOfUPlk/FO9fpTFpF+jgs=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=