2014-03-23 06:13:23 -04:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package avatar_test
|
2014-03-23 00:24:09 -04:00
|
|
|
|
|
|
|
import (
|
2014-03-24 09:16:00 -04:00
|
|
|
"errors"
|
2014-03-23 06:13:23 -04:00
|
|
|
"os"
|
2014-03-23 00:24:09 -04:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2014-03-23 06:13:23 -04:00
|
|
|
|
|
|
|
"github.com/gogits/gogs/modules/avatar"
|
2014-03-24 09:16:00 -04:00
|
|
|
"github.com/gogits/gogs/modules/log"
|
2014-03-23 00:24:09 -04:00
|
|
|
)
|
|
|
|
|
2014-03-23 06:13:23 -04:00
|
|
|
const TMPDIR = "test-avatar"
|
|
|
|
|
2014-03-23 00:24:09 -04:00
|
|
|
func TestFetch(t *testing.T) {
|
2014-03-23 06:13:23 -04:00
|
|
|
os.Mkdir(TMPDIR, 0755)
|
|
|
|
defer os.RemoveAll(TMPDIR)
|
|
|
|
|
|
|
|
hash := avatar.HashEmail("ssx205@gmail.com")
|
|
|
|
a := avatar.New(hash, TMPDIR)
|
|
|
|
a.UpdateTimeout(time.Millisecond * 200)
|
2014-03-23 00:24:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFetchMany(t *testing.T) {
|
2014-03-23 06:13:23 -04:00
|
|
|
os.Mkdir(TMPDIR, 0755)
|
|
|
|
defer os.RemoveAll(TMPDIR)
|
|
|
|
|
2014-03-24 09:16:00 -04:00
|
|
|
t.Log("start")
|
2014-03-23 06:13:23 -04:00
|
|
|
var n = 5
|
2014-03-23 00:24:09 -04:00
|
|
|
ch := make(chan bool, n)
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
go func(i int) {
|
2014-03-23 06:13:23 -04:00
|
|
|
hash := avatar.HashEmail(strconv.Itoa(i) + "ssx205@gmail.com")
|
|
|
|
a := avatar.New(hash, TMPDIR)
|
|
|
|
a.Update()
|
2014-03-24 09:16:00 -04:00
|
|
|
t.Log("finish", hash)
|
2014-03-23 00:24:09 -04:00
|
|
|
ch <- true
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
<-ch
|
|
|
|
}
|
2014-03-24 09:16:00 -04:00
|
|
|
t.Log("end")
|
2014-03-23 00:24:09 -04:00
|
|
|
}
|
2014-03-23 06:13:23 -04:00
|
|
|
|
|
|
|
// cat
|
|
|
|
// wget http://www.artsjournal.com/artfulmanager/wp/wp-content/uploads/2013/12/200x200xmirror_cat.jpg.pagespeed.ic.GOZSv6v1_H.jpg -O default.jpg
|
|
|
|
/*
|
|
|
|
func TestHttp(t *testing.T) {
|
|
|
|
http.Handle("/", avatar.HttpHandler("./", "default.jpg"))
|
|
|
|
http.ListenAndServe(":8001", nil)
|
|
|
|
}
|
|
|
|
*/
|
2014-03-24 09:16:00 -04:00
|
|
|
|
|
|
|
func TestLogTrace(t *testing.T) {
|
|
|
|
log.Trace("%v", errors.New("console log test"))
|
|
|
|
}
|