-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
39 lines (32 loc) · 929 Bytes
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"testing"
"github.com/alr-lab/test-double-go/service"
)
const email = "fake"
// SpyStore describes a spying datastore, a datastore which allows us to
// know if specific methods were called.
type SpyStore struct {
getCustomerEmailCalled bool
}
// GetCustomerEmail returns a customer email.
//
// The spying method is recording that the production-ready method would
// have been called. An alternative is to actually count the number of
// times a method was called and expect it to be called a specific number
// of times after the test execution.
func (s *SpyStore) GetCustomerEmail(id int) string {
s.getCustomerEmailCalled = true
return email
}
func TestService_Get(t *testing.T) {
spy := SpyStore{}
serv := service.New(&spy)
got := serv.Get()
if got != email {
t.Fatalf("got %q, want %q", got, email)
}
if !spy.getCustomerEmailCalled {
t.Fatal("GetCustomerEmail not called")
}
}