diff --git a/CHANGELOG.md b/CHANGELOG.md index 1506bd4..b891aa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/e2e_test.go b/e2e_test.go new file mode 100644 index 0000000..3a2f3bf --- /dev/null +++ b/e2e_test.go @@ -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") +} diff --git a/go.mod b/go.mod index 58381d7..aa40d01 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fe272af..05577df 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index dbd71bc..443a41e 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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...")