Company
Date Published
Author
Andrei Matei
Word count
1033
Language
English
Hacker News points
None

Summary

Testing complex systems in Go can be challenging due to dependency cycles that arise when multiple modules are involved, as seen in CockroachDB's codebase. A common issue is the circular dependency between the sql and server packages, which prevents sql tests from leveraging server code to set up test servers. The initial solution involved using Go's black box testing to break the dependency cycle, but it required exposing internal package details, leading to inefficiencies. To address this, a shim layer was introduced, allowing sql tests to access server functionalities through a separate module, testingshim, which does not depend on either package directly. This approach utilizes Go's black box testing and the TestMain function for setup, enabling sql tests to indirectly access server capabilities without creating dependency issues. This method simplifies test writing and can be applied to other packages facing similar challenges in Go codebases.