From 6f8577e204f044110ba6e8bd106917993bcf12e2 Mon Sep 17 00:00:00 2001 From: Joe Kralicky Date: Tue, 4 Jan 2022 11:20:39 -0500 Subject: [PATCH] Add error check for invalid/nil parameters to DescribeTable --- table_dsl.go | 4 +++- types/errors.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/table_dsl.go b/table_dsl.go index d3029f157..0db0e7180 100644 --- a/table_dsl.go +++ b/table_dsl.go @@ -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{}): diff --git a/types/errors.go b/types/errors.go index 6873f74db..2ab48200f 100644 --- a/types/errors.go +++ b/types/errors.go @@ -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),