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

Function Test_userExampleHandler_Create

internal/handler/userExample_test.go:86–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func Test_userExampleHandler_Create(t *testing.T) {
87 h := newUserExampleHandler()
88 defer h.Close()
89 testData := &types.CreateUserExampleRequest{}
90 _ = copier.Copy(testData, h.TestData.(*model.UserExample))
91
92 h.MockDao.SQLMock.ExpectBegin()
93 args := h.MockDao.GetAnyArgs(h.TestData)
94 h.MockDao.SQLMock.ExpectExec("INSERT INTO .*").
95 WithArgs(args[:len(args)-1]...). // adjusted for the amount of test data
96 WillReturnResult(sqlmock.NewResult(1, 1))
97 h.MockDao.SQLMock.ExpectCommit()
98
99 result := &httpcli.StdResult{}
100 err := httpcli.Post(result, h.GetRequestURL("Create"), testData)
101 if err != nil {
102 t.Fatal(err)
103 }
104
105 t.Logf("%+v", result)
106 // delete the templates code start
107 result = &httpcli.StdResult{}
108 testData = &types.CreateUserExampleRequest{
109 Name: "foo",
110 Password: "f447b20a7fcbf53a5d5be013ea0b15af",
111 Email: "foo@bar.com",
112 Phone: "+8616000000001",
113 Avatar: "http://foo/1.jpg",
114 Age: 10,
115 Gender: 1,
116 }
117 err = httpcli.Post(result, h.GetRequestURL("Create"), testData)
118 if err != nil {
119 t.Fatal(err)
120 }
121 t.Logf("%+v", result)
122
123 h.MockDao.SQLMock.ExpectBegin()
124 h.MockDao.SQLMock.ExpectCommit()
125 // create error test
126 result = &httpcli.StdResult{}
127 err = httpcli.Post(result, h.GetRequestURL("Create"), testData)
128 assert.Error(t, err)
129 // delete the templates code end
130}
131
132func Test_userExampleHandler_DeleteByID(t *testing.T) {
133 h := newUserExampleHandler()

Callers

nothing calls this directly

Calls 8

CopyFunction · 0.92
PostFunction · 0.92
newUserExampleHandlerFunction · 0.85
GetAnyArgsMethod · 0.80
GetRequestURLMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65
FatalMethod · 0.45

Tested by

no test coverage detected