Как правильно написать следующий тест?
Чтобы не писать внутри самого пакета
var _ Common = (*Stuff)(nil),
var _ Common2 = (*Stuff)(nil)
var _ Common3 = (*Stuff)(nil)
...
``
пакетвещи
вещи / общие.го
package stuff
type Common interface {
String() string
}
вещи / общие2.go
package stuff
type Common2 interface {
String2() string
}
stuff / stuff_suite_test.go
package stuff
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func Test(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Stuff")
}
stuff / stuff_test.go
package stuff
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
}
var _ = Describe("Stuff", func() {
It("implements Common", func() {
var s interface{} = &Stuff{}
_, ok := s.(Common)
Expect(ok).To(Equal(true))
})
})
It("implements Common 2", func() {
var _ Common2 = (*Stuff)(nil) // ok
})
stuff / stuff.go
package stuff
type Stuff struct {}
func (s *Stuff) String() string {
return ""
}
пакет lib
/ lib / lib.go
import "stuff"
func GetCommon() *stuff.Stuff {
return &stuff.Stuff{}
}
/ lib / lib_suite_test.go
package lib
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func Test(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Lib")
}
/ lib / lib_test.go
package lib
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Lib", func() {
It("can be created", func() {
l := GetCommon()
Expect(l).NotTo(BeNil())
})
}