Skip to content

Commit

Permalink
fix canary after config changes (#4056)
Browse files Browse the repository at this point in the history
Canaries has been failing with `handlers may not take more than two
arguments, but handler takes 3: errorString null` error
  • Loading branch information
wdbaruni committed Jun 5, 2024
1 parent 0e0325b commit 41970fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
41 changes: 27 additions & 14 deletions ops/aws/canary/lambda/pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func WithConfig(cfg types.BacalhauConfig) Option {
}
}

func Route(ctx context.Context, event models.Event, opts ...Option) error {
func Route(ctx context.Context, event models.Event) error {
return RouteWithOpts(ctx, event)
}

func RouteWithOpts(ctx context.Context, event models.Event, opts ...Option) error {
// NB(forrest): settings is required to allow this method to be called with or without config.
// The lambda runs expect this method to instantiate a repo and config then run. No config is provided.
// Conversely, TestScenariosAgainstDevstack creates a devstack and needs to provide
Expand All @@ -44,21 +48,11 @@ func Route(ctx context.Context, event models.Event, opts ...Option) error {
for _, opt := range opts {
opt(settings)
}
if settings.cfg == nil {
repoPath, err := os.MkdirTemp("", "bacalhau_canary_repo_*")
if err != nil {
return fmt.Errorf("failed to create repo dir: %s", err)
}

c := config.New()
// init system configs and repo.
if _, err := setup.SetupBacalhauRepo(repoPath, c); err != nil {
return fmt.Errorf("failed to initialize bacalhau repo: %s", err)
}

resolvedCfg, err := c.Current()
if settings.cfg == nil {
resolvedCfg, err := loadConfig()
if err != nil {
return err
return fmt.Errorf("failed to load config: %s", err)
}
settings.cfg = &resolvedCfg
}
Expand All @@ -73,3 +67,22 @@ func Route(ctx context.Context, event models.Event, opts ...Option) error {
log.Info().Msgf("testcase %s passed", event.Action)
return nil
}

func loadConfig() (types.BacalhauConfig, error) {
repoPath, err := os.MkdirTemp("", "bacalhau_canary_repo_*")
if err != nil {
return types.BacalhauConfig{}, fmt.Errorf("failed to create repo dir: %s", err)
}

c := config.New()
// init system configs and repo.
if _, err := setup.SetupBacalhauRepo(repoPath, c); err != nil {
return types.BacalhauConfig{}, fmt.Errorf("failed to initialize bacalhau repo: %s", err)
}

resolvedCfg, err := c.Current()
if err != nil {
return types.BacalhauConfig{}, err
}
return resolvedCfg, nil
}
2 changes: 1 addition & 1 deletion ops/aws/canary/lambda/pkg/test/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestScenariosAgainstDevstack(t *testing.T) {
for name := range router.TestcasesMap {
t.Run(name, func(t *testing.T) {
event := models.Event{Action: name}
err := router.Route(context.Background(), event, router.WithConfig(c))
err := router.RouteWithOpts(context.Background(), event, router.WithConfig(c))
require.NoError(t, err)
})
}
Expand Down

0 comments on commit 41970fe

Please sign in to comment.