diff --git a/extensions/table/table_entry.go b/extensions/table/table_entry.go index 5fa645bcee..4badfa312f 100644 --- a/extensions/table/table_entry.go +++ b/extensions/table/table_entry.go @@ -22,12 +22,14 @@ func (t TableEntry) generateIt(itBody reflect.Value) { return } - values := []reflect.Value{} + values := make([]reflect.Value, 0) + itBodyType := itBody.Type() + for i, param := range t.Parameters { var value reflect.Value if param == nil { - inType := itBody.Type().In(i) + inType := itBodyType.In(i) value = reflect.Zero(inType) } else { value = reflect.ValueOf(param) @@ -36,14 +38,34 @@ func (t TableEntry) generateIt(itBody reflect.Value) { values = append(values, value) } - body := func() { - itBody.Call(values) + var ( + body interface{} + timeout []float64 + ) + + if itBodyType.NumIn() >= 1 && itBodyType.In(0).Kind() == reflect.Chan && + itBodyType.In(0).Elem().Kind() == reflect.Interface { + + lenValues := len(values) + if lenValues > 0 && values[lenValues-1].Kind() == reflect.Float64 { + timeout = append(timeout, values[lenValues-1].Interface().(float64)) + values = values[:lenValues-1] + } + + body = func(done chan<- interface{}) { + values = append([]reflect.Value{reflect.ValueOf(done)}, values...) + itBody.Call(values) + } + } else { + body = func() { + itBody.Call(values) + } } if t.Focused { - ginkgo.FIt(t.Description, body) + ginkgo.FIt(t.Description, body, timeout...) } else { - ginkgo.It(t.Description, body) + ginkgo.It(t.Description, body, timeout...) } } diff --git a/extensions/table/table_test.go b/extensions/table/table_test.go index b008e432ba..5f8038943c 100644 --- a/extensions/table/table_test.go +++ b/extensions/table/table_test.go @@ -3,10 +3,11 @@ package table_test import ( "strings" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/Antonov-guap/ginkgo/extensions/table" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "time" ) var _ = Describe("Table", func() { @@ -19,6 +20,23 @@ var _ = Describe("Table", func() { Entry("x < y", 0, 1, false), ) + DescribeTable("a simple table with async flow", + func(done Done, msg string, after time.Duration) { //use done Done in params to make async flow + c := make(chan string, 0) + + go func(c chan string) { + time.Sleep(after) + c <- "Hello, " + msg + }(c) + + Expect(<-c).To(ContainSubstring(msg)) + + close(done) + }, + Entry("Sam", "Sam", 100*time.Millisecond), //default timeout 1 sec + 100ms latency + Entry("John", "John", 1050*time.Millisecond, 1.2), //set timeout 1.2 sec (last param) + 1050ms latency + ) + type ComplicatedThings struct { Superstructure string Substructure string