Skip to content

Commit

Permalink
Add end-to-end tests (#151)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gammazero authored Jul 8, 2024
1 parent 1907ca5 commit 4737f6f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The following emojis are used to highlight certain changes:

### Added

- Simple end-to-end test to check that trustless-gateway-domains are set correctly.

### Changed

### Removed
Expand Down
72 changes: 72 additions & 0 deletions e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main_test

import (
"context"
"fmt"
"path/filepath"
"runtime"
"testing"
"time"

testcmd "github.com/ipfs/go-test/cmd"
"github.com/stretchr/testify/require"
)

const (
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)
}

ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

runner := testcmd.NewRunner(t, t.TempDir())

// install rainbow
runner.Run(ctx, "go", "install", ".")
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")
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")
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/go-metrics-interface v0.0.1
github.com/ipfs/go-metrics-prometheus v0.0.2
github.com/ipfs/go-test v0.0.2
github.com/ipfs/go-unixfsnode v1.9.0
github.com/ipld/go-codec-dagpb v1.6.0
github.com/libp2p/go-libp2p v0.35.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZa
github.com/ipfs/go-metrics-prometheus v0.0.2/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnzdSH3u5UVlCdqSXnEks=
github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg=
github.com/ipfs/go-peertaskqueue v0.8.1/go.mod h1:Oxxd3eaK279FxeydSPPVGHzbwVeHjatZ2GA8XD+KbPU=
github.com/ipfs/go-test v0.0.2 h1:Wdxl4bKEdjEM8SLiulXMHlAQwHYOhX3CSBoUoEvncmM=
github.com/ipfs/go-test v0.0.2/go.mod h1:qhIM1EluEfElKKM6fnWxGn822/z9knUGM1+I/OAQNKI=
github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU=
github.com/ipfs/go-unixfs v0.4.5/go.mod h1:BIznJNvt/gEx/ooRMI4Us9K8+qeGO7vx1ohnbk8gjFg=
github.com/ipfs/go-unixfsnode v1.9.0 h1:ubEhQhr22sPAKO2DNsyVBW7YB/zA8Zkif25aBvz8rc8=
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ share the same seed as long as the indexes are different.
}

quit := make(chan os.Signal, 3)
signal.Notify(
quit,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGHUP,
)

var wg sync.WaitGroup
wg.Add(2)

Expand Down Expand Up @@ -575,12 +582,6 @@ share the same seed as long as the indexes are different.
}

sddaemon.SdNotify(false, sddaemon.SdNotifyReady)
signal.Notify(
quit,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGHUP,
)
<-quit
sddaemon.SdNotify(false, sddaemon.SdNotifyStopping)
goLog.Info("Closing servers...")
Expand Down

0 comments on commit 4737f6f

Please sign in to comment.