generated from yuan-h-1994/drone-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_test.go
49 lines (42 loc) · 979 Bytes
/
hello_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
43
44
45
46
47
48
49
package main
import (
"testing"
"fmt"
"context"
)
type DataStore interface {
FindUser(ctx context.Context, id int) (*User, error)
CreateUser(ctx context.Context, name string) error
}
type User struct {
id int
name string
}
type MockUserDataStore struct{}
func NewMockDataStore() DataStore {
return &MockUserDataStore{}
}
func (m *MockUserDataStore) FindUser(ctx context.Context, id int) (*User, error) {
return &User{
id: 1,
name: "test user",
}, nil
}
func (m *MockUserDataStore) CreateUser(ctx context.Context, name string) error {
fmt.Println("create user. dummy")
return nil
}
func TestHello(t *testing.T) {
if "Hello World" != getHello() {
t.Fatal("failed test")
}
storage := NewMockDataStore()
user, err := storage.FindUser(context.TODO(), 1)
if user.id != 1 {
t.Fatal(err)
}
err1 := storage.CreateUser(context.TODO(), "1")
if err1 != nil {
t.Fatal(err)
}
}