-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
42 lines (34 loc) · 966 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
40
41
42
package main
import (
"testing"
"github.com/alr-lab/test-double-go/service"
)
const (
emailDefault = ""
emailValidUser = "fake"
)
// FakeStore describes a fake datastore, a datastore which is doing some
// kind of logic but not the one that we might expect in production. It
// allows us to take shortcuts and return errors to validate the behaviour
// of the system under test during the test execution.
type FakeStore struct{}
// GetCustomerEmail returns a customer email.
//
// Here there is a simple logic of testing its argument and returning data
// accordingly. We could also return an error or add more data to be
// returned.
func (s FakeStore) GetCustomerEmail(id int) string {
email := emailDefault
switch id {
case 42:
email = emailValidUser
}
return email
}
func TestService_Get(t *testing.T) {
serv := service.New(FakeStore{})
got := serv.Get()
if got != emailValidUser {
t.Fatalf("got %q, want %q", got, emailValidUser)
}
}