Temporary filesystem only visible to the process in Go


I am writing e2e tests for a command line app where I have to do file manipulation (such as cp, mv, rm, touch, and mkdir). The tests can execute just fine in my local environment. The problem occurs when they are executed on the server across platforms, where the file manipulation gets interfered with each other. Questions are:

  1. It seems wrong to have shell command in test code to begin with, should I just code the commands programmatically?
  2. If above is yes, is there something that would work as a "temporary file system" that is only visible for the process? So that when the tests run on other platforms, the files would not get messed up?
  3. It seems like mutex lock can work as well but it would slow down the entire build.

Sorry this is more of a general and specific question at the same time. Doubt there will be a perfect answer but would love to hear some suggestions and opinions as I am new in both Go and testing. Appreciate the help!


There is nothing wrong in using OS commands in your code otherwise these will not be available to be used, although it may be incompatible depending on the target environment and as you are facing now may have some restrictions.
One tool that can work as a layer to the file commands is Afero, where you can use it even to simulate in-memory operations and S3 resources.

Answered By – Marcel Kohls

Answer Checked By – Gilberto Lyons (GoLangFix Admin)

Leave a Reply

Your email address will not be published.