Suppose I am writing a package that is in its own module, and I want
to test it. Not with unit tests, but with a larger program that uses
other non-standard packages as well.
Before modules, I would develop the package in ~/go/src, write the
test program somewhere else, and import the package. This doesn't work
with modules.
What does work is move the test program into a subdirectory of the
package, add that directory to .gitignore . This works, as long as the
test program doesn't need any non-standard packages that the package I
am writing needs.
When the test program needs more non-standard packages, I need to add
these to go.mod of the package I am developing, even though that
package itself doesn't need it.
When I give the directory with the test program its own go.mod then it
can't use the files in the parent directory as the imported package.
I turned it the other way around. I put the package I am writing in a
subdirectory of the test program. That works, as long as that subdirectory
doesn't have its own go.mod .
So, in one setup, I end up with a package with a go.mod with too many
dependencies. An in the other I end up with a package without a go.mod .
How do I get this right?
Is there a way to tell go.mod that it should use local files instead
of a repository, just for the development phase?