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