I am using gradle as the build tool for a terraform project. I do have unit tests written in go for the project under the ..test/... folder . The way I am running test locally is just on the commandline go test ..test/..
' which will run all tests
under the test folder. I want to integrate this in the build , so that every build will run this command 'go test ..test/..'
, How do I achieve this in gradle. Can a custom task be utilized to run a go
command?
I am trying to do something like the following
task testExec(type: Exec) {
workingDir "${buildDir}/test"
commandLine 'go','test'
} doLast {
println "Test Executed!"
}
But I get the error
> A problem occurred starting process 'command 'go''
For what its worth , I tried other commands and get the same erorr for ex
task testExec(type: Exec) {
workingDir "${buildDir}/test"
commandLine 'echo','${}buildDir'
} doLast {
println "Test Executed!"
}
gives similar error
> A problem occurred starting process 'command 'echo''
You can use the gradle plugin. First you can follow the starting guide and add the plugin:
Then you can run the following command to execute all go files that follow the file name convention
<name>_test.go
:Otherwise you can also create a complete custom task or a custom task with the plugin.
EDIT:
I found the cause of your error. The variable
buildDir
refers to thebuild
folder in your project:<project_folder>/build
. The problem now is that the foldertest
does not exists and the exception is thrown. Instead, you can use the variableprojectDir
.