MCPcopy Create free account
hub / github.com/cloudbase/garm / TestCreateUserDBCreateErr

Method TestCreateUserDBCreateErr

database/sql/users_test.go:176–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174}
175
176func (s *UserTestSuite) TestCreateUserDBCreateErr() {
177 s.Fixtures.SQLMock.ExpectBegin()
178 s.Fixtures.SQLMock.
179 ExpectQuery(regexp.QuoteMeta("SELECT * FROM `users` WHERE username = ? AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT ?")).
180 WithArgs(s.Fixtures.NewUserParams.Username, 1).
181 WillReturnRows(sqlmock.NewRows([]string{"id"}))
182 s.Fixtures.SQLMock.
183 ExpectQuery(regexp.QuoteMeta("SELECT * FROM `users` WHERE email = ? AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT ?")).
184 WithArgs(s.Fixtures.NewUserParams.Email, 1).
185 WillReturnRows(sqlmock.NewRows([]string{"id"}))
186 s.Fixtures.SQLMock.
187 ExpectExec("INSERT INTO `users`").
188 WillReturnError(fmt.Errorf("creating user mock error"))
189 s.Fixtures.SQLMock.ExpectRollback()
190
191 _, err := s.StoreSQLMocked.CreateUser(context.Background(), s.Fixtures.NewUserParams)
192
193 s.Require().NotNil(err)
194 s.Require().Equal("error creating user: error creating user: creating user mock error", err.Error())
195 s.assertSQLMockExpectations()
196}
197
198func (s *UserTestSuite) TestHasAdminUserNoAdmin() {
199 hasAdmin := s.Store.HasAdminUser(context.Background())

Callers

nothing calls this directly

Calls 3

CreateUserMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected