ONSdigital / dp-mongodb-in-memory

Runs an in-memory MongoDB instance for Go unit tests
MIT License
15 stars 13 forks source link

Handle mongod startup errors #7

Closed rafahop closed 3 years ago

rafahop commented 3 years ago

What

Log all mongod messages and handle them so to ensure the server is running when Start returns an object. Let mongo find a free port to use (by passing --port 0) and wait for the logs to report it. Note Mongo uses structured logging only from version 4.4 which is the lower we support hence there is no problem with the format of the logs.

How to review

Check the code and run the tests. Logs should show mongod messages

Who can review

Anyone, not me

stmuk commented 3 years ago

Looks good but a couple of suggestions:-

staticcheck ./... suggests "main.go:158:14: should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (S1028)"

Also maybe add a explicit comment about the use of port 0 to get a random unused port for those unfamiliar with this since the behaviour of the zero value is a bit magical!