On Fri, Apr 21, 2017 at 12:37 PM, st ov <
so.q...@gmail.com> wrote:
>
> So lets say I have a package that relies on a configuration.
> In my dev environment I run 'go test' against the package and the
> configurations for dev.
> It passes the tests so I build out this package and artifact the resulting
> binary.
>
> This artifact then continues to a staging environment that has its own
> configurations.
> I was wondering if its possible to run those same tests against the binary
> instead of having the source rebuild?
> This is to verify that the binary works across different environments.
>
> Or am I approaching this incorrectly?
I see. No, `go test` doesn't work that way. `go test` builds a
testing version of the package, and tests that. There is no way to
run the same tests from a normal non-testing version of the package.
It's a perfectly reasonable request, it's just not what `go test`
does. Given an external program, you will have to write tests that
test that program, which is not the usual way that `go test` works.
That said, it is possible to use `go test` and have the tests build
and test the program. Then you could use a flag to specify which
program to test, use `go test -c` to build a test binary, and run that
test binary with the flag. You would only be able to test external
behavior, things you can do by running the program, rather than
testing internals as you can normally do with `go test`. In the
standard repository, some of the cmd/go tests are written this way;
see src/cmd/go/go_test.go. It doesn't have the flag to choose the
binary to test, but that would be a minor addition.
Ian