aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go
diff options
context:
space:
mode:
authordependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>2020-06-15 10:21:06 +0000
committerDaniel J Walsh <dwalsh@redhat.com>2020-06-15 08:35:25 -0400
commit68eca3c19e010882f7c82b70437f4edbbbfeca3d (patch)
tree174f45a2fb583fa07a183083ff180c406ca74fc0 /vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go
parentc2690c24530d202c5fef07bc8ef7b3d3c5ad747c (diff)
downloadpodman-68eca3c19e010882f7c82b70437f4edbbbfeca3d.tar.gz
podman-68eca3c19e010882f7c82b70437f4edbbbfeca3d.tar.bz2
podman-68eca3c19e010882f7c82b70437f4edbbbfeca3d.zip
Bump github.com/onsi/ginkgo from 1.12.3 to 1.13.0
Bumps [github.com/onsi/ginkgo](https://github.com/onsi/ginkgo) from 1.12.3 to 1.13.0. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v1.12.3...v1.13.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go')
-rw-r--r--vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go94
1 files changed, 71 insertions, 23 deletions
diff --git a/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go b/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go
index 1a919a1fe..783e7964a 100644
--- a/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go
+++ b/vendor/github.com/onsi/ginkgo/extensions/table/table_entry.go
@@ -1,6 +1,7 @@
package table
import (
+ "fmt"
"reflect"
"github.com/onsi/ginkgo/internal/codelocation"
@@ -12,7 +13,7 @@ import (
TableEntry represents an entry in a table test. You generally use the `Entry` constructor.
*/
type TableEntry struct {
- Description string
+ Description interface{}
Parameters []interface{}
Pending bool
Focused bool
@@ -26,33 +27,56 @@ func (t TableEntry) generateIt(itBody reflect.Value) {
t.codeLocation = codelocation.New(5)
}
- if t.Pending {
- global.Suite.PushItNode(t.Description, func() {}, types.FlagTypePending, t.codeLocation, 0)
- return
+ var description string
+ descriptionValue := reflect.ValueOf(t.Description)
+ switch descriptionValue.Kind() {
+ case reflect.String:
+ description = descriptionValue.String()
+ case reflect.Func:
+ values := castParameters(descriptionValue, t.Parameters)
+ res := descriptionValue.Call(values)
+ if len(res) != 1 {
+ panic(fmt.Sprintf("The describe function should return only a value, returned %d", len(res)))
+ }
+ if res[0].Kind() != reflect.String {
+ panic(fmt.Sprintf("The describe function should return a string, returned %#v", res[0]))
+ }
+ description = res[0].String()
+ default:
+ panic(fmt.Sprintf("Description can either be a string or a function, got %#v", descriptionValue))
}
- values := make([]reflect.Value, len(t.Parameters))
- iBodyType := itBody.Type()
- for i, param := range t.Parameters {
- if param == nil {
- inType := iBodyType.In(i)
- values[i] = reflect.Zero(inType)
- } else {
- values[i] = reflect.ValueOf(param)
- }
+ if t.Pending {
+ global.Suite.PushItNode(description, func() {}, types.FlagTypePending, t.codeLocation, 0)
+ return
}
+ values := castParameters(itBody, t.Parameters)
body := func() {
itBody.Call(values)
}
if t.Focused {
- global.Suite.PushItNode(t.Description, body, types.FlagTypeFocused, t.codeLocation, global.DefaultTimeout)
+ global.Suite.PushItNode(description, body, types.FlagTypeFocused, t.codeLocation, global.DefaultTimeout)
} else {
- global.Suite.PushItNode(t.Description, body, types.FlagTypeNone, t.codeLocation, global.DefaultTimeout)
+ global.Suite.PushItNode(description, body, types.FlagTypeNone, t.codeLocation, global.DefaultTimeout)
}
}
+func castParameters(function reflect.Value, parameters []interface{}) []reflect.Value {
+ res := make([]reflect.Value, len(parameters))
+ funcType := function.Type()
+ for i, param := range parameters {
+ if param == nil {
+ inType := funcType.In(i)
+ res[i] = reflect.Zero(inType)
+ } else {
+ res[i] = reflect.ValueOf(param)
+ }
+ }
+ return res
+}
+
/*
Entry constructs a TableEntry.
@@ -61,27 +85,51 @@ Subsequent parameters are saved off and sent to the callback passed in to `Descr
Each Entry ends up generating an individual Ginkgo It.
*/
-func Entry(description string, parameters ...interface{}) TableEntry {
- return TableEntry{description, parameters, false, false, codelocation.New(1)}
+func Entry(description interface{}, parameters ...interface{}) TableEntry {
+ return TableEntry{
+ Description: description,
+ Parameters: parameters,
+ Pending: false,
+ Focused: false,
+ codeLocation: codelocation.New(1),
+ }
}
/*
You can focus a particular entry with FEntry. This is equivalent to FIt.
*/
-func FEntry(description string, parameters ...interface{}) TableEntry {
- return TableEntry{description, parameters, false, true, codelocation.New(1)}
+func FEntry(description interface{}, parameters ...interface{}) TableEntry {
+ return TableEntry{
+ Description: description,
+ Parameters: parameters,
+ Pending: false,
+ Focused: true,
+ codeLocation: codelocation.New(1),
+ }
}
/*
You can mark a particular entry as pending with PEntry. This is equivalent to PIt.
*/
-func PEntry(description string, parameters ...interface{}) TableEntry {
- return TableEntry{description, parameters, true, false, codelocation.New(1)}
+func PEntry(description interface{}, parameters ...interface{}) TableEntry {
+ return TableEntry{
+ Description: description,
+ Parameters: parameters,
+ Pending: true,
+ Focused: false,
+ codeLocation: codelocation.New(1),
+ }
}
/*
You can mark a particular entry as pending with XEntry. This is equivalent to XIt.
*/
-func XEntry(description string, parameters ...interface{}) TableEntry {
- return TableEntry{description, parameters, true, false, codelocation.New(1)}
+func XEntry(description interface{}, parameters ...interface{}) TableEntry {
+ return TableEntry{
+ Description: description,
+ Parameters: parameters,
+ Pending: true,
+ Focused: false,
+ codeLocation: codelocation.New(1),
+ }
}