Unit tests for filesystem changes


I’m creating a wrapper around Git. But I’m having dificult testing it. My big problem is to know what is the best approach to test filesystem changes. How can I test if a file was deleted, changed. Also testing the outputs of the git commands.

Is there any way to mock this?

For example, if on the wrapper I have a command that wraps the “git add . && git commit -m 'some message”

How can I can I test this?


The general implementation of your wrapper itself must be testable in nature.


func Commit(...args) (Hash, error) {
  // Commits and extracts hash from output  or git log

// *_test.go
func TestCommit(t *testing.T) {
  hash, err := Commit(...args)
  // check error etc..

The thing to look out for is not to rely much on bash commands and their outputs and use any libgit2 bindings if any. I think there is go-git module that has bindings for such things.

Hi , thanks for the reply.

Unfortunally I cannot rely much on on go-git (using it in some parts of the wrapper), there’s a lot of missing basic functionality from go-git, (git merge for example) and some other things are not very usefull.

I will take a closer look at libgit2. thanks.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.