onsi / ginkgo

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

GinkgoT doenst behave like expected #1261

Closed c0ffee closed 1 year ago

c0ffee commented 1 year ago

I am trying to get Ginkgo running in co,bination with some other testhelpers. According to the documentation I would expect the following should work:

package main

import (
    "testing"

    . "github.com/onsi/ginkgo/v2"
)

func main() {
    blub(GinkgoT())
}

func blub(t *testing.T) {

}

./prog.go:12:7: cannot use GinkgoT() (value of type ginkgo.FullGinkgoTInterface) as *testing.T value in argument to blub

Am I missing something? Thanks in advance!

onsi commented 1 year ago

GinkgoT() implements an interface that is compatible with *testing.T but cannot implement an actual concrete type like *testing.T For some reason the original implementation of the testing package passed around a concrete type instead of an interface and this has never been changed.

What this means is that if you want to use GinkgoT() with some other library that expects a testing.T-like thing then the library needs to accept it’s testing.T via some sort of interface. For example here is how testify accepts its testing.T argument.

c0ffee commented 1 year ago

onsi thank you for your reply, yeh i digged deeper into it and realized i was way to naiv :s

I adapted my own functions to use an interface but at the end I have to call https://github.com/hashicorp/vault/blob/5374b3b046d13d3e7a9f6833efcaeff0e49fddc4/sdk/helper/testcluster/docker/environment.go#L398

and they are not using an interface either. so this fails at the end too

onsi commented 1 year ago

yep you’ll have to open an issue there. i’ve seen the hasicorp/vault team be fairly responsive to this exact request in the past though so hopefully it won’t be too tricky to get worked on!

c0ffee commented 1 year ago

ok lets close this here then, but for sure the next one who will stumple over it will find at least the issue ;)