-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
245 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package mock_names | ||
|
||
//go:generate mockgen -mock_names=Service=UserServiceMock -package mocks -typed -destination mocks/user_service.go -self_package go.uber.org/mock/mockgen/internal/tests/mock_name/mocks go.uber.org/mock/mockgen/internal/tests/mock_name/user Service | ||
//go:generate mockgen -mock_names=Service=PostServiceMock -package mocks -typed -destination mocks/post_service.go -self_package go.uber.org/mock/mockgen/internal/tests/mock_name/mocks go.uber.org/mock/mockgen/internal/tests/mock_name/post Service |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" | ||
user "go.uber.org/mock/mockgen/internal/tests/mock_name/user" | ||
) | ||
|
||
func TestInteract(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.Fatalf("unexpected error") | ||
} | ||
|
||
p, err := postService.Create("test title", "test body", u) | ||
if err != nil { | ||
t.Fatalf("unexpected error") | ||
} | ||
|
||
if p.Title != "test title" || p.Body != "test body" || p.Author.Name != u.Name { | ||
t.Fatalf("unexpected postService.Create result") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package post | ||
|
||
import ( | ||
"go.uber.org/mock/mockgen/internal/tests/mock_name/user" | ||
) | ||
|
||
type Post struct { | ||
Title string | ||
Body string | ||
Author *user.User | ||
} | ||
|
||
type Service interface { | ||
Create(title, body string, author *user.User) (*Post, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package user | ||
|
||
type User struct { | ||
Name string | ||
} | ||
|
||
type Service interface { | ||
Create(name string) (*User, error) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.