MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / newUserExampleService

Function newUserExampleService

internal/service/userExample_test.go:22–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20)
21
22func newUserExampleService() *gotest.Service {
23 testData := &model.UserExample{}
24 testData.ID = 1
25 // you can set the other fields of testData here, such as:
26 //testData.CreatedAt = time.Now()
27 //testData.UpdatedAt = testData.CreatedAt
28
29 // init mock cache
30 c := gotest.NewCache(map[string]interface{}{utils.Uint64ToStr(testData.ID): testData})
31 c.ICache = cache.NewUserExampleCache(&database.CacheType{
32 CType: "redis",
33 Rdb: c.RedisClient,
34 })
35
36 // init mock dao
37 d := gotest.NewDao(c, testData)
38 d.IDao = dao.NewUserExampleDao(d.DB, c.ICache.(cache.UserExampleCache))
39
40 // init mock service
41 s := gotest.NewService(d, testData)
42 serverNameExampleV1.RegisterUserExampleServer(s.Server, &userExample{
43 UnimplementedUserExampleServer: serverNameExampleV1.UnimplementedUserExampleServer{},
44 iDao: d.IDao.(dao.UserExampleDao),
45 })
46
47 // start up rpc server
48 s.GoGrpcServer()
49 time.Sleep(time.Millisecond * 100)
50
51 // grpc client
52 s.IServiceClient = serverNameExampleV1.NewUserExampleClient(s.GetClientConn())
53
54 return s
55}
56
57func Test_userExampleService_Create(t *testing.T) {
58 s := newUserExampleService()

Calls 8

GoGrpcServerMethod · 0.95
GetClientConnMethod · 0.95
NewCacheFunction · 0.92
Uint64ToStrFunction · 0.92
NewUserExampleCacheFunction · 0.92
NewDaoFunction · 0.92
NewUserExampleDaoFunction · 0.92
NewServiceFunction · 0.92

Tested by

no test coverage detected