Reputation: 371
We have a special text file on an HTTP server that contains the filenames and test functions we want to skip when our golang tests run.
I must build something which downloads that test file, parses the file names and test functions that should be skipped, and then finally runs our go tests and properly skips the test functions found in the input file.
What's the right way to make this work in golang?
(I realize this sounds like an unusual way to skip, but we really want to make this work as I have described for reasons which are out of context to this question.)
Upvotes: 2
Views: 7217
Reputation: 1424
You can skip test cases with (*testing.T).Skip() function. You can download the test file in the init function of go's test file. Then parse and load the function names in map or array. Before running each case, check if the test case is included in the skip list and skip if required.
// Psuedo code -> foo_test.go
var skipCases map[string]bool
func init() {
// download and parse test file.
// add test case names which needs skipped into skipCases map
}
func TestFoo(t *testing.T) {
if skipCases["TestFoo"] {
t.Skip()
}
// else continue testing
}
Upvotes: 7