File: user.go

package info (click to toggle)
golang-go.uber-mock 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: sh: 37; makefile: 3
file content (120 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Package user is an example package with an interface.
package user

//go:generate mockgen -destination mock_user_test.go -package user_test go.uber.org/mock/sample Index,Embed,Embedded

// Random bunch of imports to test mockgen.
import (
	"hash"
	"io"
	"log"
	"net"
	"net/http"

	btz "bytes"

	// Two imports with the same base name.
	t1 "html/template"

	t2 "text/template"

	"go.uber.org/mock/sample/imp1"

	// Dependencies outside the standard library.

	renamed2 "go.uber.org/mock/sample/imp2"

	. "go.uber.org/mock/sample/imp3"

	imp_four "go.uber.org/mock/sample/imp4"
)

// calls itself "imp_four"

// A bizarre interface to test corner cases in mockgen.
// This would normally be in its own file or package,
// separate from the user of it (e.g. io.Reader).
type Index interface {
	Get(key string) any
	GetTwo(key1, key2 string) (v1, v2 any)
	Put(key string, value any)

	// Check that imports are handled correctly.
	Summary(buf *btz.Buffer, w io.Writer)
	Other() hash.Hash
	Templates(a t1.CSS, b t2.FuncMap)

	// A method with an anonymous argument.
	Anon(string)

	// Methods using foreign types outside the standard library.
	ForeignOne(imp1.Imp1)
	ForeignTwo(renamed2.Imp2)
	ForeignThree(Imp3)
	ForeignFour(imp_four.Imp4)

	// A method that returns a nillable type.
	NillableRet() error
	// A method that returns a non-interface type.
	ConcreteRet() chan<- bool

	// Methods with an ellipsis argument.
	Ellip(fmt string, args ...any)
	EllipOnly(...string)

	// A method with a pointer argument that we will set.
	Ptr(arg *int)

	// A method with a slice argument and an array return.
	Slice(a []int, b []byte) [3]int

	// A method with channel arguments.
	Chan(a chan int, b chan<- hash.Hash)

	// A method with a function argument.
	Func(f func(http.Request) (int, bool))

	// A method with a map argument.
	Map(a map[int]hash.Hash)

	// Methods with an unnamed empty struct argument.
	Struct(a struct{})          // not so likely
	StructChan(a chan struct{}) // a bit more common
}

// An interface with an embedded interface.
type Embed interface {
	RegularMethod()
	Embedded
	imp1.ForeignEmbedded
}

type Embedded interface {
	EmbeddedMethod()
}

// some random use of another package that isn't needed by the interface.
var _ net.Addr

// A function that we will test that uses the above interface.
// It takes a list of keys and values, and puts them in the index.
func Remember(index Index, keys []string, values []any) {
	for i, k := range keys {
		index.Put(k, values[i])
	}
	err := index.NillableRet()
	if err != nil {
		log.Fatalf("Woah! %v", err)
	}
	if len(keys) > 0 && keys[0] == "a" {
		index.Ellip("%d", 0, 1, 1, 2, 3)
		index.Ellip("%d", 1, 3, 6, 10, 15)
		index.EllipOnly("arg")
	}
}

func GrabPointer(index Index) int {
	var a int
	index.Ptr(&a)
	return a
}