git-ecosystem / git-bundle-server

A web server & management CLI to host Git bundles for use with Git's "bundle URIs" feature
Other
43 stars 20 forks source link

Unit test GetRepositories() #11

Closed derrickstolee closed 1 year ago

derrickstolee commented 1 year ago

I set out to learn more about Go and the unit testing framework that @vdye set up in github/git-fundamentals#9, with a focus on picking a very simple method from our core package: GetRepositories().

Along the way, @vdye helped me find a way to move a significant portion of shared_test.go into another place that can be reused in multiple places. Specifically, we will need the mocked structures. I use MockFileSystem in this PR, and had to extend it for the filesystem methods used in GetRepositories().

Important things to note:

  1. In order to "export" things across packages, the type and method names must start with a capital letter. They must also not be in a file ending with _test.go.
  2. We can avoid using a package name in every instance of a type using . "<package>" in the import statement. This avoids an even worse transformation in the existing tests, which are already converting many lowercase types and methods into uppercase.

Hopefully this large change to take the core of our unit-testing strategy and make it accessible to other packages will be relatively stable in future iterations. Then, we can hopefully result in more involved unit tests in the future that test things like the bundling strategy.