vendredi 27 mai 2016

how to test a golang library that takes an executable using itself as an argument?

I am writing a library with methods that you can use to write a server executable and a client executable. I am also writing a "main" package that uses the library to implement those executables.

My simplest question is, how do people normally write tests for golang executables? A main_test.go or similar seems to be non-existant in the handful of other people's packages I looked at.

I'm also in the perhaps unusual situation where my server code internally needs to run instances of (one type of) the client (my server spawns clients). So my server library method that does all the server work (listen for connections from clients and respond to them) needs* to take the name of (path to) the client executable as an argument. But of course, while testing this library code I don't have an installed client executable. How do I test in this situation?

In particular, I am using go's built-in tools for testing, ie. go test ./my_library.

[*] or is there an alternative way of structuring things?

Aucun commentaire:

Enregistrer un commentaire