Skip to content

Commit

Permalink
Add IPNI Endpoint Flag to Daemon
Browse files Browse the repository at this point in the history
Closes #409 by adding the IPNI Endpoint Flag to the Daemon and adds a positive/negative test for the flag on the daemon.

Adding the positive/negative test required changing the exit command on 119 of daemon.go to pass the err on up.  Please review and confirm this won't introduce any unintentional side effects.
  • Loading branch information
jtsmedley authored and rvagg committed Sep 7, 2023
1 parent 43cc107 commit 768f669
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/lassie/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var daemonFlags = []cli.Flag{
DefaultText: "no limit",
EnvVars: []string{"LASSIE_CONCURRENT_SP_RETRIEVALS"},
},
FlagIPNIEndpoint,
FlagEventRecorderAuth,
FlagEventRecorderInstanceId,
FlagEventRecorderUrl,
Expand Down Expand Up @@ -115,7 +116,7 @@ func daemonAction(cctx *cli.Context) error {

lassieCfg, err := buildLassieConfigFromCLIContext(cctx, lassieOpts, libp2pOpts)
if err != nil {
return cli.Exit(err, 1)
return err
}

// http server config
Expand Down Expand Up @@ -165,7 +166,6 @@ func defaultDaemonRun(
httpServerCfg httpserver.HttpServerConfig,
eventRecorderCfg *aggregateeventrecorder.EventRecorderConfig,
) error {

lassie, err := lassie.NewLassieWithConfig(ctx, lassieCfg)
if err != nil {
return nil
Expand Down
35 changes: 31 additions & 4 deletions cmd/lassie/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

a "github.com/filecoin-project/lassie/pkg/aggregateeventrecorder"
"github.com/filecoin-project/lassie/pkg/indexerlookup"
l "github.com/filecoin-project/lassie/pkg/lassie"
h "github.com/filecoin-project/lassie/pkg/server/http"
"github.com/libp2p/go-libp2p/core/peer"
Expand All @@ -17,9 +18,10 @@ import (

func TestDaemonCommandFlags(t *testing.T) {
tests := []struct {
name string
args []string
assert daemonRunFunc
name string
args []string
shouldError bool
assert daemonRunFunc
}{
{
name: "with default args",
Expand Down Expand Up @@ -149,6 +151,19 @@ func TestDaemonCommandFlags(t *testing.T) {
return nil
},
},
{
name: "with ipni endpoint",
args: []string{"daemon", "--ipni-endpoint", "https://cid.contact"},
assert: func(ctx context.Context, lCfg *l.LassieConfig, hCfg h.HttpServerConfig, erCfg *a.EventRecorderConfig) error {
require.IsType(t, &indexerlookup.IndexerCandidateFinder{}, lCfg.Finder, "finder should be an IndexerCandidateFinder when providing an ipni endpoint")
return nil
},
},
{
name: "with bad ipni endpoint",
args: []string{"daemon", "--ipni-endpoint", "not-a-url"},
shouldError: true,
},
{
name: "with event recorder url",
args: []string{"daemon", "--event-recorder-url", "https://myeventrecorder.com/v1/retrieval-events"},
Expand Down Expand Up @@ -185,6 +200,10 @@ func TestDaemonCommandFlags(t *testing.T) {

for _, test := range tests {
daemonRun = test.assert
if test.shouldError {
daemonRun = noopDaemonRun
}

app := &cli.App{
Name: "cli-test",
Flags: daemonFlags,
Expand All @@ -193,9 +212,17 @@ func TestDaemonCommandFlags(t *testing.T) {

t.Run(test.name, func(t *testing.T) {
err := app.Run(append([]string{"cli-test"}, test.args...))
if err != nil {
if err != nil && !test.shouldError {
t.Fatal(err)
}

if err == nil && test.shouldError {
t.Fatal("expected error")
}
})
}
}

func noopDaemonRun(ctx context.Context, lCfg *l.LassieConfig, hCfg h.HttpServerConfig, erCfg *a.EventRecorderConfig) error {
return nil
}

0 comments on commit 768f669

Please sign in to comment.