@@ -0,0 +1,47 @@ |
|
|
|
1 |
+package alias |
|
2 |
+ |
|
3 |
+//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Fooer,FooerAlias,Barer,BarerAlias,Bazer,QuxerConsumer,QuuxerConsumer |
|
4 |
+ |
|
5 |
+import "go.uber.org/mock/mockgen/internal/tests/alias/subpkg" |
|
6 |
+ |
|
7 |
+// Case 1: A interface that has alias references in this package |
|
8 |
+// should still be generated for its underlying name, i.e., MockFooer, |
|
9 |
+// even though we have the alias replacement logic. |
|
10 |
+type Fooer interface { |
|
11 |
+Foo() |
|
12 |
+} |
|
13 |
+ |
|
14 |
+// Case 2: Generating a mock for an alias type. |
|
15 |
+type FooerAlias = Fooer |
|
16 |
+ |
|
17 |
+// Case 3: Generate mock for an interface that takes in alias parameters |
|
18 |
+// and returns alias results. |
|
19 |
+type Barer interface{ |
|
20 |
+Bar(FooerAlias) FooerAlias |
|
21 |
+} |
|
22 |
+ |
|
23 |
+// Case 4: Combination of cases 2 & 3. |
|
24 |
+type BarerAlias = Barer |
|
25 |
+ |
|
26 |
+// Case 5: Generate mock for an interface that actually returns |
|
27 |
+// the underlying type. This will generate mocks that use the alias, |
|
28 |
+// but that should be fine since they should be interchangeable. |
|
29 |
+type Bazer interface{ |
|
30 |
+Baz(Fooer) Fooer |
|
31 |
+} |
|
32 |
+ |
|
33 |
+// Case 6: Generate mock for a type that refers to an alias defined in this package |
|
34 |
+// for a type from another package. |
|
35 |
+// The generated methods should use the alias defined here. |
|
36 |
+type QuxerAlias = subpkg.Quxer |
|
37 |
+ |
|
38 |
+type QuxerConsumer interface{ |
|
39 |
+Consume(QuxerAlias) QuxerAlias |
|
40 |
+} |
|
41 |
+ |
|
42 |
+// Case 7: Generate mock for a type that refers to an alias defined in another package |
|
43 |
+// for an unexported type in that other package. |
|
44 |
+// The generated method should only use the alias, not the unexported underlying name. |
|
45 |
+type QuuxerConsumer interface{ |
|
46 |
+Consume(subpkg.Quuxer) subpkg.Quuxer |
|
47 |
+} |