Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rzajac/zltest
Package zltest provides facilities to test zerolog log messages.
https://github.com/rzajac/zltest
golang testing zerolog
Last synced: 3 days ago
JSON representation
Package zltest provides facilities to test zerolog log messages.
- Host: GitHub
- URL: https://github.com/rzajac/zltest
- Owner: rzajac
- License: bsd-2-clause
- Created: 2020-10-05T09:07:05.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-27T20:15:58.000Z (almost 3 years ago)
- Last Synced: 2024-06-18T23:03:38.321Z (5 months ago)
- Topics: golang, testing, zerolog
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 19
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Report Card](https://goreportcard.com/badge/github.com/rzajac/zltest)](https://goreportcard.com/report/github.com/rzajac/zltest)
[![GoDoc](https://img.shields.io/badge/api-Godoc-blue.svg)](https://pkg.go.dev/github.com/rzajac/zltest)Logging is an integral part of most applications and as such it has tobe tested.
Package `zltest` provides facilities to test
[zerolog](https://github.com/rs/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
```go
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