MCPcopy
hub / github.com/marmotedu/iam / TestUserController_Get

Function TestUserController_Get

internal/apiserver/controller/v1/user/get_test.go:20–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestUserController_Get(t *testing.T) {
21 user := &v1.User{
22 ObjectMeta: metav1.ObjectMeta{
23 Name: "admin",
24 ID: 0,
25 },
26 Nickname: "admin",
27 Password: "Admin@2020",
28 Email: "admin@foxmail.com",
29 }
30
31 c, _ := gin.CreateTestContext(httptest.NewRecorder())
32 c.Request, _ = http.NewRequest("GET", "/v1/users/colin", nil)
33 c.Params = []gin.Param{{Key: "name", Value: "admin"}}
34
35 ctrl := gomock.NewController(t)
36 defer ctrl.Finish()
37
38 mockService := srvv1.NewMockService(ctrl)
39 mockUserSrv := srvv1.NewMockUserSrv(ctrl)
40 mockUserSrv.EXPECT().Get(gomock.Any(), gomock.Eq("admin"), gomock.Any()).Return(user, nil)
41 mockService.EXPECT().Users().Return(mockUserSrv)
42
43 type fields struct {
44 srv srvv1.Service
45 }
46 type args struct {
47 c *gin.Context
48 }
49 tests := []struct {
50 name string
51 fields fields
52 args args
53 }{
54 {
55 name: "default",
56 fields: fields{
57 srv: mockService,
58 },
59 args: args{
60 c: c,
61 },
62 },
63 }
64 for _, tt := range tests {
65 t.Run(tt.name, func(t *testing.T) {
66 u := &UserController{
67 srv: tt.fields.srv,
68 }
69 u.Get(tt.args.c)
70 })
71 }
72}

Callers

nothing calls this directly

Calls 6

EXPECTMethod · 0.95
EXPECTMethod · 0.95
GetMethod · 0.95
GetMethod · 0.65
UsersMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…