Skip to content

Commit 4737f6f

Browse files
authored
Add end-to-end tests (#151)
* Add end-to-end tests * use ipfs/go-test * Set up signal handler sooner to that sigint right after start does not crash daemon * Update CHANGELOG Add basic end-to-end tests to rainbow. This is not a complete set of tests but is a place to start adding end-to-end tests. Fixes #89
1 parent 1907ca5 commit 4737f6f

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The following emojis are used to highlight certain changes:
1515

1616
### Added
1717

18+
- Simple end-to-end test to check that trustless-gateway-domains are set correctly.
19+
1820
### Changed
1921

2022
### Removed

e2e_test.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"path/filepath"
7+
"runtime"
8+
"testing"
9+
"time"
10+
11+
testcmd "github.com/ipfs/go-test/cmd"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
const (
16+
startTimeout = 5 * time.Second
17+
testTimeout = 15 * time.Second
18+
)
19+
20+
func TestEndToEndTrustlessGatewayDomains(t *testing.T) {
21+
switch runtime.GOOS {
22+
case "windows":
23+
t.Skip("skipping test on", runtime.GOOS)
24+
}
25+
26+
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
27+
defer cancel()
28+
29+
runner := testcmd.NewRunner(t, t.TempDir())
30+
31+
// install rainbow
32+
runner.Run(ctx, "go", "install", ".")
33+
rainbow := filepath.Join(runner.Dir, "rainbow")
34+
35+
args := testcmd.Args(rainbow, "--trustless-gateway-domains", "example.org")
36+
ready := testcmd.NewStdoutWatcher("IPFS Gateway listening")
37+
domain := testcmd.NewStdoutWatcher("RAINBOW_TRUSTLESS_GATEWAY_DOMAINS = example.org")
38+
cmdRainbow := runner.Start(ctx, args, ready, domain)
39+
40+
startCtx, startCancel := context.WithTimeout(context.Background(), startTimeout)
41+
defer startCancel()
42+
43+
err := ready.Wait(startCtx)
44+
require.NoError(t, err)
45+
t.Log("Rainbow is running")
46+
47+
err = domain.Wait(startCtx)
48+
require.NoError(t, err)
49+
t.Log("Correct value set by cli flag --trustless-gateway-domains")
50+
51+
runner.Stop(cmdRainbow, 5*time.Second)
52+
t.Log("Rainbow stopped")
53+
54+
runner.Env = append(runner.Env, fmt.Sprintf("%s=%s", "RAINBOW_TRUSTLESS_GATEWAY_DOMAINS", "example.com"))
55+
domain = testcmd.NewStdoutWatcher("RAINBOW_TRUSTLESS_GATEWAY_DOMAINS = example.com")
56+
cmdRainbow = runner.Start(ctx, testcmd.Args(rainbow), ready, domain)
57+
58+
startCancel()
59+
startCtx, startCancel = context.WithTimeout(context.Background(), startTimeout)
60+
defer startCancel()
61+
62+
err = ready.Wait(startCtx)
63+
require.NoError(t, err)
64+
t.Log("Rainbow is running")
65+
66+
err = domain.Wait(startCtx)
67+
require.NoError(t, err)
68+
t.Log("Correct value set by environ var RAINBOW_TRUSTLESS_GATEWAY_DOMAINS")
69+
70+
runner.Stop(cmdRainbow, 5*time.Second)
71+
t.Log("Rainbow stopped")
72+
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/ipfs/go-log/v2 v2.5.1
2121
github.com/ipfs/go-metrics-interface v0.0.1
2222
github.com/ipfs/go-metrics-prometheus v0.0.2
23+
github.com/ipfs/go-test v0.0.2
2324
github.com/ipfs/go-unixfsnode v1.9.0
2425
github.com/ipld/go-codec-dagpb v1.6.0
2526
github.com/libp2p/go-libp2p v0.35.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZa
311311
github.com/ipfs/go-metrics-prometheus v0.0.2/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnzdSH3u5UVlCdqSXnEks=
312312
github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg=
313313
github.com/ipfs/go-peertaskqueue v0.8.1/go.mod h1:Oxxd3eaK279FxeydSPPVGHzbwVeHjatZ2GA8XD+KbPU=
314+
github.com/ipfs/go-test v0.0.2 h1:Wdxl4bKEdjEM8SLiulXMHlAQwHYOhX3CSBoUoEvncmM=
315+
github.com/ipfs/go-test v0.0.2/go.mod h1:qhIM1EluEfElKKM6fnWxGn822/z9knUGM1+I/OAQNKI=
314316
github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU=
315317
github.com/ipfs/go-unixfs v0.4.5/go.mod h1:BIznJNvt/gEx/ooRMI4Us9K8+qeGO7vx1ohnbk8gjFg=
316318
github.com/ipfs/go-unixfsnode v1.9.0 h1:ubEhQhr22sPAKO2DNsyVBW7YB/zA8Zkif25aBvz8rc8=

main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ share the same seed as long as the indexes are different.
512512
}
513513

514514
quit := make(chan os.Signal, 3)
515+
signal.Notify(
516+
quit,
517+
syscall.SIGINT,
518+
syscall.SIGTERM,
519+
syscall.SIGHUP,
520+
)
521+
515522
var wg sync.WaitGroup
516523
wg.Add(2)
517524

@@ -575,12 +582,6 @@ share the same seed as long as the indexes are different.
575582
}
576583

577584
sddaemon.SdNotify(false, sddaemon.SdNotifyReady)
578-
signal.Notify(
579-
quit,
580-
syscall.SIGINT,
581-
syscall.SIGTERM,
582-
syscall.SIGHUP,
583-
)
584585
<-quit
585586
sddaemon.SdNotify(false, sddaemon.SdNotifyStopping)
586587
goLog.Info("Closing servers...")

0 commit comments

Comments
 (0)