Run all tests in a single go file
You can use sed to find all the test functions in a go file to pass to the regex flag:
// my_api_test.go
package my_api
func TestHappyPath(t *testing.T) {
}
func TestSadPath(t *testing.T) {
}
func TestHorriblePath(t *testing.T) {
}
func TestAwesomePath(t *testing.T) {
}
Test command:
go test -run $(sed -n 's/func.*\(Test.*\)(.*/\1/p' my_api_test.go | xargs | sed 's/ /|/g')
This runs:
go test -run TestHappyPath|TestSadPath|TestHorriblePath|TestAwesomePath