onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.12k stars 644 forks source link

feature proposal: WhenTable #1324

Open maguro opened 7 months ago

maguro commented 7 months ago

I very much would like DescribeTable to behave like a container, e.g.

DescribeTable("a k8s heartbeat request arrives",
    func(endStream bool) {
        It("is ignored when processing downstream headers", func() {
            status := filter.DecodeHeaders(reqH, endStream)
            Ω(status).Should(Equal(api.Continue))
        })

        It("is ignored when processing downstream data", func() {
            buffer := mockenvoy.NewBufferInstance(GinkgoT())

            status := filter.DecodeData(buffer, endStream)
            Ω(status).Should(Equal(api.Continue))
        })
    },
    Entry("stream is still live", false),
    Entry("stream has ended", true),
)

But that won't work for obvious reasons. I proposed we add WhenTable:

WhenTable("a k8s heartbeat request arrives",
    func(endStream bool) {
        It("is ignored when processing downstream headers", func() {
            status := filter.DecodeHeaders(reqH, endStream)
            Ω(status).Should(Equal(api.Continue))
        })

        It("is ignored when processing downstream data", func() {
            buffer := mockenvoy.NewBufferInstance(GinkgoT())

            status := filter.DecodeData(buffer, endStream)
            Ω(status).Should(Equal(api.Continue))
        })
    },
    Entry("stream is still live", false),
    Entry("stream has ended", true),
)
blgm commented 7 months ago

Hi @maguro. Have you thought about dynamically generating specs? It’s something that you could do right now without waiting for a feature to be implemented.

https://onsi.github.io/ginkgo/#dynamically-generating-specs

onsi commented 7 months ago

hey @maguro this sounds like a great idea. i took a look and it was actually relatively easy to implement. I've added DescribeTableSubtree - please take a look at the latest commit on master and the docs here and let me know what you think. I'd love it if you could give it a try and make sure it works for you before I cut a release.