Reputation: 630
I have an Extractor
interface that has a Playlist
method:
// extractor.go
package extractor
type Extractor interface {
Playlist(timestampFrom int64) (playlist.Tracklist, error)
}
I'm using this interface in another package:
// fip.go
package fip
type Extractor struct {
}
func (extractor Extractor) Playlist(timestampFrom int64) ([]playlist.Track, error) {
// ...
}
And in my tests, I'd like to show an example on how to use the Playlist
method for the fip
package:
// fip_test.go
package fip
func ExamplePlaylist() {
// ...
}
But go vet
shows this error:
fip/extractor_test.go:82:1: ExamplePlaylist refers to unknown identifier: Playlist
I don't understand why... Playlist
does exist as a method in the fip
package. What am I missing?
If more context is needed, see these files with the full source:
https://github.com/coaxial/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/fip/fip.go
https://github.com/coaxial/tizinger/blob/8016d52a1278cf44dde13d518c6a15a18cb29774/fip/fip_test.go
Upvotes: 4
Views: 1699
Reputation: 21095
The correct name for the example function is ExampleExtractor_Playlist
as described in the examples section of the testing docs.
Quoting:
The naming convention to declare examples for the package, a function F, a type T and method M on type T are:
func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }
Your example is the last case where T
is Extractor
and M
is Playlist
.
Upvotes: 8