-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend gomock to allow passing an source_importpath instead of librar…
…y when operating in source mode (#3822) Co-authored-by: Josh Smith <[email protected]>
- Loading branch information
Showing
14 changed files
with
140 additions
and
11 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
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
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
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,17 @@ | ||
gomock | ||
===================== | ||
|
||
Tests that ensure the gomock rules can be called correctly under different input permutations. | ||
|
||
reflective | ||
------------------------ | ||
Checks that gomock can be run in "reflective" mode when passed a `GoLibrary` and `interfaces`. | ||
|
||
source | ||
------------------------ | ||
Checks that gomock can be run in "source" mode when passed a `GoLibrary` and `source`. | ||
|
||
source_with_importpath | ||
------------------------ | ||
Checks that gomock can be run in "source" mode when passed an `importpath` and `source`. | ||
This test case also demonstrates the circumstance in which `importpath` is necessary to prevent a circular dependency. |
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,34 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "gomock") | ||
|
||
go_library( | ||
name = "client", | ||
srcs = [ | ||
"client.go", | ||
], | ||
importpath = "github.com/bazelbuild/rules_go/gomock/client", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@org_golang_google_genproto//googleapis/bytestream", | ||
"@org_golang_google_grpc//:grpc", | ||
], | ||
) | ||
|
||
# Build the mocks using reflective mode (i.e. without passing source) | ||
gomock( | ||
name = "mocks", | ||
out = "client_mock.go", | ||
library = ":client", | ||
package = "client", | ||
interfaces = ["Client"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_test( | ||
name = "client_test", | ||
srcs = [ | ||
"client_mock.go", | ||
"client_test.go", | ||
], | ||
embed = [":client"], | ||
deps = ["@com_github_golang_mock//gomock"], | ||
) |
File renamed without changes.
1 change: 0 additions & 1 deletion
1
tests/extras/gomock/client_test.go → ...s/extras/gomock/reflective/client_test.go
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
package client | ||
|
||
var _ Client = (*MockClient)(nil) | ||
var _ ClientWrapper = (*MockClientWrapper)(nil) |
File renamed without changes.
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,10 @@ | ||
package client | ||
|
||
import ( | ||
"google.golang.org/genproto/googleapis/bytestream" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type Client interface { | ||
Connect(grpc.ClientConnInterface) *bytestream.ByteStreamClient | ||
} |
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,3 @@ | ||
package client | ||
|
||
var _ Client = (*MockClient)(nil) |
File renamed without changes.
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,37 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "gomock") | ||
|
||
# For this test, the mock is included as part of the library | ||
go_library( | ||
name = "client", | ||
srcs = [ | ||
"client.go", | ||
"client_mock.go", | ||
], | ||
importpath = "github.com/bazelbuild/rules_go/gomock/client", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@org_golang_google_genproto//googleapis/bytestream", | ||
"@org_golang_google_grpc//:grpc", | ||
"@com_github_golang_mock//gomock", | ||
], | ||
) | ||
|
||
# Pass importpath instead of library to the generation step | ||
# Passing library instead of importpath here will cause a circular dependency | ||
gomock( | ||
name = "mocks", | ||
out = "client_mock.go", | ||
source_importpath = "github.com/bazelbuild/rules_go/gomock/client", | ||
package = "client", | ||
source = "client.go", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# Don't include client_mock.go as a source file, instead use it from the library | ||
go_test( | ||
name = "client_test", | ||
srcs = [ | ||
"client_test.go", | ||
], | ||
embed = [":client"], | ||
) |
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,10 @@ | ||
package client | ||
|
||
import ( | ||
"google.golang.org/genproto/googleapis/bytestream" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type Client interface { | ||
Connect(grpc.ClientConnInterface) *bytestream.ByteStreamClient | ||
} |
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,3 @@ | ||
package client | ||
|
||
var _ Client = (*MockClient)(nil) |