Skip to content
/ zltest Public

Package zltest provides facilities to test zerolog log messages.

License

Notifications You must be signed in to change notification settings

rzajac/zltest

Repository files navigation

Go Report Card GoDoc

Logging is an integral part of most applications and as such it has tobe tested. Package zltest provides facilities to test zerolog log messages.

In general zltest.Tester provides methods to test values (or existence) of specific fields in logged messages.

Installation

go get github.com/rzajac/zltest

Examples

func Test_ServiceLogsProperly(t *testing.T) {
    // --- Given ---
    // Crate zerolog test helper. 
    tst := zltest.New(t)

    // Configure zerolog and pas tester as a writer.     
    log := zerolog.New(tst).With().Timestamp().Logger()
    
    // Inject log to tested service or package.
    srv := MyService(log)

    // --- When ---
    srv.ExecuteSomeLogic()

    // --- Then ---

    // Test if log messages were generated properly.
    ent := tst.LastEntry()
    ent.ExpNum("key0", 123)
    ent.ExpMsg("message")
    ent.ExpLevel(zerolog.ErrorLevel)
}

License

BSD-2-Clause

About

Package zltest provides facilities to test zerolog log messages.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages