openstorage icon indicating copy to clipboard operation
openstorage copied to clipboard

No globally created objects

Open lpabon opened this issue 7 years ago • 1 comments

Having globally created objects makes it almost impossible to write simple unit tests. Here is an example:

To test nodeStatus is really hard since it calls nodeStatusIntl which calls cluster.Inst() and that returns a global variable.

This needs to be fixed so that objects are returned and managed, that way tests are simple to write.

lpabon avatar Nov 16 '17 01:11 lpabon

Yes, this makes sense. Note however that almost all methods in cluster.go file are using cluster.Inst() to do their work, so this issue is by no means isolated. Perhaps a better approach to tackle the "testability", is to allow to override the cached Singleton instance, so cluster.Inst() could return a mock-object, w/ predictable results.

Apropos, can anyone recommend any good mocking frameworks for Go? (ie. Java has have really awesome mockito and powermock frameworks, but I could not find anything similar to their flexibility in golang)

zoxpx avatar Nov 16 '17 02:11 zoxpx