Closed nkakouros closed 5 years ago
I ended up copying any needed file for a test to TEST_GO_ROOTDIR/...
. I am leaving this open just in case @mbland has some insight to share.
Closing this as the design of the testing framework is indeed great and my solution is sufficient for my use case.
Due diligence
Framework, Bash, and operating system version information
Description
When creating a test go script using
@go.create_test_go_script()
and usingrun "$TEST_GO_SCRIPT"
, the paths are set so that the actual directory where the project's modules are is not taken into account when resolving the path to a module.For example:
will fail with an error like:
The reason is that the test go script is in a directory different to the actual project's go script. As a result the
_GO_ROOTDIR=${0%/*}
variable is set to the temporary test directory and the_GO_SCRIPTS_DIR
is then resolved relative to that directory.A way to avoid this error is to set the
TEST_GO_ROOTDIR
,TEST_GO_SCRIPTS_RELATIVE_DIR
, etc mentioned inlib/testing/environment
to custom values in a customenvironment
file so that effectively theTEST_*
paths coincide with the actual_GO_*
paths. But this defeats the purpose of theTEST_*
variables (as I understand it) which is to create a sandbox directory where transient files will be written to and deleted without the fear of messing up the actual project.Is my understanding of the above correct? Is this behavior by design or a limitation of the current design? In the latter case, there could be one more variable,
TEST_REAL_GO_ROOTDIR
that, if set, will set_GO_ROOTDIR
ingo-core.bash
directly (as opposed to reading it from $0).Edit: My use case is that my entry go script loads a number of modules regardless of the command. Then, a command might use a function that requires 4 modules. That could mean ~8 modules for a function to run correctly. It seems to me that copying or stubbing all 8 modules just to test one function is not the appropriate solution. But I might be wrong.