MCPcopy Create free account
hub / github.com/gogs/gogs / usersChangeUsername

Function usersChangeUsername

internal/database/users_test.go:229–357  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *UsersStore)

Source from the content-addressed store, hash-verified

227}
228
229func usersChangeUsername(t *testing.T, ctx context.Context, s *UsersStore) {
230 alice, err := s.Create(
231 ctx,
232 "alice",
233 "alice@example.com",
234 CreateUserOptions{
235 Activated: true,
236 },
237 )
238 require.NoError(t, err)
239
240 t.Run("name not allowed", func(t *testing.T) {
241 err := s.ChangeUsername(ctx, alice.ID, "-")
242 wantErr := ErrNameNotAllowed{
243 args: errutil.Args{
244 "reason": "reserved",
245 "name": "-",
246 },
247 }
248 assert.Equal(t, wantErr, err)
249 })
250
251 t.Run("name already exists", func(t *testing.T) {
252 bob, err := s.Create(
253 ctx,
254 "bob",
255 "bob@example.com",
256 CreateUserOptions{
257 Activated: true,
258 },
259 )
260 require.NoError(t, err)
261
262 err = s.ChangeUsername(ctx, alice.ID, bob.Name)
263 wantErr := ErrUserAlreadyExist{
264 args: errutil.Args{
265 "name": bob.Name,
266 },
267 }
268 assert.Equal(t, wantErr, err)
269 })
270
271 tempRepositoryRoot := filepath.Join(os.TempDir(), "usersChangeUsername-tempRepositoryRoot")
272 conf.SetMockRepository(
273 t,
274 conf.RepositoryOpts{
275 Root: tempRepositoryRoot,
276 },
277 )
278 err = os.RemoveAll(tempRepositoryRoot)
279 require.NoError(t, err)
280 defer func() { _ = os.RemoveAll(tempRepositoryRoot) }()
281
282 tempServerAppDataPath := filepath.Join(os.TempDir(), "usersChangeUsername-tempServerAppDataPath")
283 conf.SetMockServer(
284 t,
285 conf.ServerOpts{
286 AppDataPath: tempServerAppDataPath,

Callers

nothing calls this directly

Calls 13

SetMockRepositoryFunction · 0.92
SetMockServerFunction · 0.92
UserPathFunction · 0.92
RepositoryLocalPathFunction · 0.92
RepositoryLocalWikiPathFunction · 0.92
ExistFunction · 0.92
newReposStoreFunction · 0.85
ChangeUsernameMethod · 0.80
ExecMethod · 0.80
WhereMethod · 0.80
UpdateMethod · 0.65
GetByIDMethod · 0.65

Tested by

no test coverage detected