globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

Respect nil slices, maps in bson encoder #147

Closed aksentyev closed 6 years ago

aksentyev commented 6 years ago

Hi! BSON package initializes nil slices and maps by default. It makes using reflect.DeepEqual or test assertions non trivial task. This PR allowes to enable or disable the feature of using null's for not initialized slices and maps (e.g. with make()). This change does not change the default behaviour of bson.Marshal/bson.Unmarshal so it has backward compatibility with previous versions of the package.

domodwyer commented 6 years ago

Hi @aksentyev

This is fantastic - I've personally been burnt by this loads of times writing integration tests! Thanks for another great PR.

Dom

aksentyev commented 6 years ago

@domodwyer Unfortunately, this change breaks SASL Authentification, I need some time to investigate and improve changes.

tadukurow commented 6 years ago

@aksentyev thanks for the PR, just one question. Why did the sasl code have to be updated?

returning nil instead of []byte{} on an error path seems to be the correct thing.

aksentyev commented 6 years ago

@tadukurow I agree, fixed)

domodwyer commented 6 years ago

Hi @aksentyev

Would you pull the latest dev in and we'll merge?

Sorry for the delay - we've been super busy - thanks for opening this PR!

Dom