(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func 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 | |
| 132 | func Test_userExampleHandler_DeleteByID(t *testing.T) { |
| 133 | h := newUserExampleHandler() |
nothing calls this directly
no test coverage detected