Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
fix the test by checking the CI variable in the real main, not in the…
Browse files Browse the repository at this point in the history
… test, and dying if we see the CI variable
  • Loading branch information
eyedeekay committed Aug 21, 2024
1 parent 32ddf2a commit 2602355
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 66 deletions.
5 changes: 5 additions & 0 deletions contrib/dendrite-demo-i2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"flag"
"os"
"time"

"github.com/getsentry/sentry-go"
Expand All @@ -40,9 +41,13 @@ import (
)

var samAddr = flag.String("samaddr", "127.0.0.1:7656", "Address to connect to the I2P SAMv3 API")
var _, skip = os.LookupEnv("CI")

func main() {
cfg := setup.ParseFlags(true)
if skip {
return
}

configErrors := &config.ConfigErrors{}
cfg.Verify(configErrors)
Expand Down
62 changes: 29 additions & 33 deletions contrib/dendrite-demo-i2p/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,39 @@ import (
// 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
func TestMain(t *testing.T) {
if _, ex := os.LookupEnv("CI"); ex {
t.Skip("skipping test, as no TOR/I2P client is available")
} else {
t.Log("running locally, continuing with tests")
var (
args []string
)
var (
args []string
)

for _, arg := range os.Args {
switch {
case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"):
default:
args = append(args, arg)
}
}
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
for _, arg := range os.Args {
switch {
case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"):
default:
args = append(args, arg)
}
}

// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
t.Log(args)

waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
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)
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)

select {
case <-signalCh:
return
case <-waitCh:
return
}
select {
case <-signalCh:
return
case <-waitCh:
return
}
}

7 changes: 6 additions & 1 deletion contrib/dendrite-demo-tor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"os"
"time"

"github.com/getsentry/sentry-go"
Expand All @@ -38,9 +39,13 @@ import (
"github.com/matrix-org/dendrite/userapi"
)

var _, skip = os.LookupEnv("CI")

func main() {
cfg := setup.ParseFlags(true)

if skip {
return
}
configErrors := &config.ConfigErrors{}
cfg.Verify(configErrors)
if len(*configErrors) > 0 {
Expand Down
61 changes: 29 additions & 32 deletions contrib/dendrite-demo-tor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,39 @@ import (
// 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
func TestMain(t *testing.T) {
if _, ex := os.LookupEnv("CI"); ex {
t.Skip("skipping test, as no TOR/I2P client is available")
} else {
t.Log("running locally, continuing with tests")
var (
args []string
)
var (
args []string
)

for _, arg := range os.Args {
switch {
case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"):
default:
args = append(args, arg)
}
}
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
for _, arg := range os.Args {
switch {
case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"):
default:
args = append(args, arg)
}
}

waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()
// only run the tests if there are args to be passed
if len(args) <= 1 {
return
}
t.Log(args)

signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
waitCh := make(chan int, 1)
os.Args = args
go func() {
main()
close(waitCh)
}()

select {
case <-signalCh:
return
case <-waitCh:
return
}
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)

select {
case <-signalCh:
return
case <-waitCh:
return
}
}

0 comments on commit 2602355

Please sign in to comment.