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

Function usersIsUsernameUsed

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

Source from the content-addressed store, hash-verified

844}
845
846func usersIsUsernameUsed(t *testing.T, ctx context.Context, s *UsersStore) {
847 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
848 require.NoError(t, err)
849
850 tests := []struct {
851 name string
852 username string
853 excludeUserID int64
854 want bool
855 }{
856 {
857 name: "no change",
858 username: alice.Name,
859 excludeUserID: alice.ID,
860 want: false,
861 },
862 {
863 name: "change case",
864 username: strings.ToUpper(alice.Name),
865 excludeUserID: alice.ID,
866 want: false,
867 },
868 {
869 name: "not used",
870 username: "bob",
871 excludeUserID: alice.ID,
872 want: false,
873 },
874 {
875 name: "not used when not excluded",
876 username: "bob",
877 excludeUserID: 0,
878 want: false,
879 },
880
881 {
882 name: "used when not excluded",
883 username: alice.Name,
884 excludeUserID: 0,
885 want: true,
886 },
887 }
888 for _, test := range tests {
889 t.Run(test.name, func(t *testing.T) {
890 got := s.IsUsernameUsed(ctx, test.username, test.excludeUserID)
891 assert.Equal(t, test.want, got)
892 })
893 }
894}
895
896func usersList(t *testing.T, ctx context.Context, s *UsersStore) {
897 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})

Callers

nothing calls this directly

Calls 2

IsUsernameUsedMethod · 0.80
CreateMethod · 0.45

Tested by

no test coverage detected