Skip to content

Commit

Permalink
Catch nil Mapper funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
sam boyer committed Jul 23, 2023
1 parent db0ad40 commit f330c61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,16 @@ func (ml *maybeLineage) checkLensesOrder() error {
}

func (ml *maybeLineage) checkGoLensCompleteness() error {
// TODO(sdboyer) it'd be nice to consolidate all the errors so that the user always sees a complete set of problems
all := make(map[lensID]bool)
for _, lens := range ml.implens {
id := lid(lens.To, lens.From)
if all[id] {
return fmt.Errorf("duplicate Go migration %s", id)
}
if lens.Mapper == nil {
return fmt.Errorf("nil Go migration func for %s", id)
}
all[id] = true
}

Expand Down
7 changes: 6 additions & 1 deletion gomig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ schemas: [{
}
tex, tname := ex, name
t.Run(tname, func(t *testing.T) {
t.Log(start.Version(), end.Version())
tinst, lacunas, err := tex.Translate(end.Version())
require.NoError(t, err)
assert.Nil(t, lacunas, "pure go migrations cannot emit lacunas")
Expand Down Expand Up @@ -360,6 +359,12 @@ schemas: [{
Mapper: func(inst *Instance, to Schema) (*Instance, error) { return nil, nil },
})...))
assert.Error(t, err, "expected error when providing Go migration for minor version upgrade")

_, err = BindLineage(linval, rt, ImperativeLenses(append(correctLenses[:1], ImperativeLens{
To: SV(2, 0),
From: SV(1, 1),
})...))
assert.Error(t, err, "expected error when Mapper func is nil")
})
}

Expand Down

0 comments on commit f330c61

Please sign in to comment.