mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-24 08:20:31 +08:00
Add TestSyncAvatarsFromGitHub().
This commit is contained in:
parent
cc8485a7db
commit
bc368a4361
@ -25,6 +25,15 @@ import (
|
||||
|
||||
var adapter *Adapter
|
||||
|
||||
func InitConfig() {
|
||||
err := beego.LoadAppConfig("ini", "../conf/app.conf")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
InitAdapter()
|
||||
}
|
||||
|
||||
func InitAdapter() {
|
||||
adapter = NewAdapter("mysql", beego.AppConfig.String("dataSourceName"))
|
||||
}
|
||||
|
31
object/user_test.go
Normal file
31
object/user_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"xorm.io/core"
|
||||
)
|
||||
|
||||
func updateUserAvatar(user *User) bool {
|
||||
affected, err := adapter.engine.ID(core.PK{user.Owner, user.Name}).Cols("avatar").Update(user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func TestSyncAvatarsFromGitHub(t *testing.T) {
|
||||
InitConfig()
|
||||
|
||||
users := GetGlobalUsers()
|
||||
for _, user := range users {
|
||||
if user.Github == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
user.Avatar = fmt.Sprintf("https://avatars.githubusercontent.com/%s", user.Github)
|
||||
updateUserAvatar(user)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user