Skip to content

Commit

Permalink
Add error check for invalid/nil parameters to DescribeTable
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky authored and onsi committed Jan 4, 2022
1 parent ae6bc14 commit 6f8577e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion table_dsl.go
Expand Up @@ -135,8 +135,10 @@ func generateTable(description string, args ...interface{}) {
return "Entry: " + strings.Join(out, ", ")
}

for _, arg := range args {
for i, arg := range args {
switch t := reflect.TypeOf(arg); {
case t == nil:
exitIfErr(types.GinkgoErrors.IncorrectParameterTypeForTable(i, "nil", cl))
case t == reflect.TypeOf(TableEntry{}):
entries = append(entries, arg.(TableEntry))
case t == reflect.TypeOf([]TableEntry{}):
Expand Down
9 changes: 9 additions & 0 deletions types/errors.go
Expand Up @@ -370,6 +370,15 @@ func (g ginkgoErrors) InvalidEntryDescription(cl CodeLocation) error {
}
}

func (g ginkgoErrors) IncorrectParameterTypeForTable(i int, name string, cl CodeLocation) error {
return GinkgoError{
Heading: "DescribeTable passed incorrect parameter type",
Message: fmt.Sprintf("Parameter #%d passed to DescribeTable is of incorrect type <%s>", i, name),
CodeLocation: cl,
DocLink: "table-specs",
}
}

func (g ginkgoErrors) TooFewParametersToTableFunction(expected, actual int, kind string, cl CodeLocation) error {
return GinkgoError{
Heading: fmt.Sprintf("Too few parameters passed in to %s", kind),
Expand Down

0 comments on commit 6f8577e

Please sign in to comment.