Files

36 lines
770 B
Go
Raw Permalink Normal View History

package eprel
import (
"context"
"testing"
)
// stubFetcher verifies the Fetcher interface is usable from processing tests.
type stubFetcher struct {
enabled bool
data *Data
err error
calls int
lastID string
}
func (s *stubFetcher) Enabled() bool { return s.enabled }
func (s *stubFetcher) Fetch(_ context.Context, id string) (*Data, error) {
s.calls++
s.lastID = id
return s.data, s.err
}
func TestFetcherInterface(t *testing.T) {
var _ Fetcher = (*Client)(nil)
var _ Fetcher = Disabled{}
var _ Fetcher = (*stubFetcher)(nil)
st := &stubFetcher{enabled: true, data: &Data{ID: "1", Label: "L"}}
got, err := st.Fetch(context.Background(), "1")
if err != nil || got.ID != "1" || st.calls != 1 {
t.Fatalf("stub: %#v err=%v", got, err)
}
}