Skip tests that require external services(Tor, I2P) when running in CI

This commit is contained in:
eyedeekay 2024-08-05 20:33:06 -04:00
parent 5098937e96
commit 11b284a639
No known key found for this signature in database
GPG key ID: D75C03B39B5E14E1
2 changed files with 70 additions and 62 deletions

View file

@ -13,38 +13,42 @@ import (
// Run the monolith: ./monolith.debug -test.coverprofile=/somewhere/to/dump/integrationcover.out DEVEL --config dendrite.yaml // Run the monolith: ./monolith.debug -test.coverprofile=/somewhere/to/dump/integrationcover.out DEVEL --config dendrite.yaml
// Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html // Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html
// Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc // Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc
func TestMain(_ *testing.T) { func TestMain(t *testing.T) {
var ( if os.Getenv("CI") != "" {
args []string t.Skip("skipping test, as no TOR/I2P client is available")
) } else {
var (
args []string
)
for _, arg := range os.Args { for _, arg := range os.Args {
switch { switch {
case strings.HasPrefix(arg, "DEVEL"): case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"): case strings.HasPrefix(arg, "-test"):
default: default:
args = append(args, arg) args = append(args, arg)
}
}
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
select {
case <-signalCh:
return
case <-waitCh:
return
} }
} }
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
select {
case <-signalCh:
return
case <-waitCh:
return
}
} }

View file

@ -13,38 +13,42 @@ import (
// Run the monolith: ./monolith.debug -test.coverprofile=/somewhere/to/dump/integrationcover.out DEVEL --config dendrite.yaml // Run the monolith: ./monolith.debug -test.coverprofile=/somewhere/to/dump/integrationcover.out DEVEL --config dendrite.yaml
// Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html // Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html
// Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc // Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc
func TestMain(_ *testing.T) { func TestMain(t *testing.T) {
var ( if os.Getenv("CI") != "" {
args []string t.Skip("skipping test, as no TOR/I2P client is available")
) } else {
var (
args []string
)
for _, arg := range os.Args { for _, arg := range os.Args {
switch { switch {
case strings.HasPrefix(arg, "DEVEL"): case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"): case strings.HasPrefix(arg, "-test"):
default: default:
args = append(args, arg) args = append(args, arg)
}
}
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
select {
case <-signalCh:
return
case <-waitCh:
return
} }
} }
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
select {
case <-signalCh:
return
case <-waitCh:
return
}
} }