File: mocks_test.go

package info (click to toggle)
golang-go.uber-mock 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: sh: 37; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (2)
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
package mock_names

import (
	"testing"

	"go.uber.org/mock/gomock"
	"go.uber.org/mock/mockgen/internal/tests/mock_name/mocks"
	"go.uber.org/mock/mockgen/internal/tests/mock_name/post"
	"go.uber.org/mock/mockgen/internal/tests/mock_name/user"
)

func TestMockNames(t *testing.T) {
	ctrl := gomock.NewController(t)

	userService := mocks.NewUserServiceMock(ctrl)
	postService := mocks.NewPostServiceMock(ctrl)

	gomock.InOrder(
		userService.EXPECT().
			Create("John Doe").
			Return(&user.User{Name: "John Doe"}, nil),
		postService.EXPECT().
			Create(gomock.Eq("test title"), gomock.Eq("test body"), gomock.Eq(&user.User{Name: "John Doe"})).
			Return(&post.Post{
				Title: "test title",
				Body:  "test body",
				Author: &user.User{
					Name: "John Doe",
				},
			}, nil))
	u, err := userService.Create("John Doe")
	if err != nil {
		t.Fatal("unexpected error")
	}

	p, err := postService.Create("test title", "test body", u)
	if err != nil {
		t.Fatal("unexpected error")
	}

	if p.Title != "test title" || p.Body != "test body" || p.Author.Name != u.Name {
		t.Fatal("unexpected postService.Create result")
	}
}