openstorage
openstorage copied to clipboard
No globally created objects
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.
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)