You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

115 rivejä
2.8 KiB

  1. //go:generate mockgen -destination mock_user/mock_user.go github.com/golang/mock/sample Index,Embed,Embedded
  2. // An example package with an interface.
  3. package user
  4. // Random bunch of imports to test mockgen.
  5. import "io"
  6. import (
  7. btz "bytes"
  8. "hash"
  9. "log"
  10. "net"
  11. "net/http"
  12. // Two imports with the same base name.
  13. t1 "html/template"
  14. t2 "text/template"
  15. )
  16. // Dependencies outside the standard library.
  17. import (
  18. "github.com/golang/mock/sample/imp1"
  19. renamed2 "github.com/golang/mock/sample/imp2"
  20. . "github.com/golang/mock/sample/imp3"
  21. "github.com/golang/mock/sample/imp4" // calls itself "imp_four"
  22. )
  23. // A bizarre interface to test corner cases in mockgen.
  24. // This would normally be in its own file or package,
  25. // separate from the user of it (e.g. io.Reader).
  26. type Index interface {
  27. Get(key string) interface{}
  28. GetTwo(key1, key2 string) (v1, v2 interface{})
  29. Put(key string, value interface{})
  30. // Check that imports are handled correctly.
  31. Summary(buf *btz.Buffer, w io.Writer)
  32. Other() hash.Hash
  33. Templates(a t1.CSS, b t2.FuncMap)
  34. // A method with an anonymous argument.
  35. Anon(string)
  36. // Methods using foreign types outside the standard library.
  37. ForeignOne(imp1.Imp1)
  38. ForeignTwo(renamed2.Imp2)
  39. ForeignThree(Imp3)
  40. ForeignFour(imp_four.Imp4)
  41. // A method that returns a nillable type.
  42. NillableRet() error
  43. // A method that returns a non-interface type.
  44. ConcreteRet() chan<- bool
  45. // Methods with an ellipsis argument.
  46. Ellip(fmt string, args ...interface{})
  47. EllipOnly(...string)
  48. // A method with a pointer argument that we will set.
  49. Ptr(arg *int)
  50. // A method with a slice argument and an array return.
  51. Slice(a []int, b []byte) [3]int
  52. // A method with channel arguments.
  53. Chan(a chan int, b chan<- hash.Hash)
  54. // A method with a function argument.
  55. Func(f func(http.Request) (int, bool))
  56. // A method with a map argument.
  57. Map(a map[int]hash.Hash)
  58. // Methods with an unnamed empty struct argument.
  59. Struct(a struct{}) // not so likely
  60. StructChan(a chan struct{}) // a bit more common
  61. }
  62. // An interface with an embedded interface.
  63. type Embed interface {
  64. RegularMethod()
  65. Embedded
  66. imp1.ForeignEmbedded
  67. }
  68. type Embedded interface {
  69. EmbeddedMethod()
  70. }
  71. // some random use of another package that isn't needed by the interface.
  72. var _ net.Addr
  73. // A function that we will test that uses the above interface.
  74. // It takes a list of keys and values, and puts them in the index.
  75. func Remember(index Index, keys []string, values []interface{}) {
  76. for i, k := range keys {
  77. index.Put(k, values[i])
  78. }
  79. err := index.NillableRet()
  80. if err != nil {
  81. log.Fatalf("Woah! %v", err)
  82. }
  83. if len(keys) > 0 && keys[0] == "a" {
  84. index.Ellip("%d", 0, 1, 1, 2, 3)
  85. index.Ellip("%d", 1, 3, 6, 10, 15)
  86. index.EllipOnly("arg")
  87. }
  88. }
  89. func GrabPointer(index Index) int {
  90. var a int
  91. index.Ptr(&a)
  92. return a
  93. }