mirror of https://github.com/gogs/gogs.git
orgsGetByName
parent
ed260cbcb9
commit
26f8ddfca0
|
@ -36,6 +36,7 @@ func TestOrganizations(t *testing.T) {
|
|||
test func(t *testing.T, ctx context.Context, db *organizations)
|
||||
}{
|
||||
{"Create", orgsCreate},
|
||||
{"GetByName", orgsGetByName},
|
||||
{"List", orgsList},
|
||||
{"SearchByName", orgsSearchByName},
|
||||
{"CountByUser", orgsCountByUser},
|
||||
|
@ -112,6 +113,33 @@ func orgsCreate(t *testing.T, ctx context.Context, db *organizations) {
|
|||
assert.Equal(t, db.NowFunc().Format(time.RFC3339), got.Updated.UTC().Format(time.RFC3339))
|
||||
}
|
||||
|
||||
func orgsGetByName(t *testing.T, ctx context.Context, db *organizations) {
|
||||
t.Run("correct user type", func(t *testing.T) {
|
||||
tempPictureAvatarUploadPath := filepath.Join(os.TempDir(), "usersGetByUsername-tempPictureAvatarUploadPath")
|
||||
conf.SetMockPicture(t, conf.PictureOpts{AvatarUploadPath: tempPictureAvatarUploadPath})
|
||||
|
||||
org1, err := db.Create(ctx, "org1", 1, CreateOrganizationOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
got, err := db.GetByName(ctx, org1.Name)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, org1.Name, got.Name)
|
||||
|
||||
_, err = db.GetByName(ctx, "bad_name")
|
||||
wantErr := ErrOrganizationNotExist{args: errutil.Args{"name": "bad_name"}}
|
||||
assert.Equal(t, wantErr, err)
|
||||
})
|
||||
|
||||
t.Run("wrong user type", func(t *testing.T) {
|
||||
alice, err := NewUsersStore(db.DB).Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.GetByName(ctx, alice.Name)
|
||||
wantErr := ErrOrganizationNotExist{args: errutil.Args{"name": alice.Name}}
|
||||
assert.Equal(t, wantErr, err)
|
||||
})
|
||||
}
|
||||
|
||||
func orgsList(t *testing.T, ctx context.Context, db *organizations) {
|
||||
usersStore := NewUsersStore(db.DB)
|
||||
alice, err := usersStore.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
|
||||
|
|
|
@ -797,9 +797,9 @@ func usersGetByUsername(t *testing.T, ctx context.Context, db *users) {
|
|||
alice, err := db.Create(ctx, "alice", "alice@exmaple.com", CreateUserOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
user, err := db.GetByUsername(ctx, alice.Name)
|
||||
got, err := db.GetByUsername(ctx, alice.Name)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, alice.Name, user.Name)
|
||||
assert.Equal(t, alice.Name, got.Name)
|
||||
|
||||
_, err = db.GetByUsername(ctx, "bad_username")
|
||||
wantErr := ErrUserNotExist{args: errutil.Args{"name": "bad_username"}}
|
||||
|
|
Loading…
Reference in New Issue