Skip to content

Commit

Permalink
Added test for mock_names parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
UnAfraid committed Dec 18, 2023
1 parent 6e30799 commit 0c6bbe9
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 14 deletions.
4 changes: 4 additions & 0 deletions mockgen/internal/tests/mock_name/mocks.go
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
80 changes: 80 additions & 0 deletions mockgen/internal/tests/mock_name/mocks/post_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions mockgen/internal/tests/mock_name/mocks/user_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions mockgen/internal/tests/mock_name/mocks_test.go
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")
}
}
15 changes: 15 additions & 0 deletions mockgen/internal/tests/mock_name/post/service.go
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)
}
9 changes: 9 additions & 0 deletions mockgen/internal/tests/mock_name/user/service.go
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)
}
28 changes: 14 additions & 14 deletions mockgen/internal/tests/typed_inorder/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c6bbe9

Please sign in to comment.