-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavatar_test.go
66 lines (59 loc) · 1.89 KB
/
avatar_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
gomniauthtest "github.com/stretchr/gomniauth/test"
"io/ioutil"
"os"
"path"
"testing"
)
func TestAuthAvatar(t *testing.T) {
var authAvatar AuthAvatar
testUser := &gomniauthtest.TestUser{}
testUser.On("AvatarURL").Return("", ErrNoAvatarURL)
testChatUser := &chatUser{User: testUser}
url, err := authAvatar.GetAvatarURL(testChatUser)
if err != ErrNoAvatarURL {
t.Error("AuthAvatar.GetAvatarURL should return ErrNoAvatarURL when no value present")
}
// set a value
testUrl := "https://en.gravatar.com/userimage/63152567/ba62a16ca597cbda50862147b17efc12.jpg"
testUser = &gomniauthtest.TestUser{}
testChatUser.User = testUser
testUser.On("AvatarURL").Return(testUrl, nil)
url, err = authAvatar.GetAvatarURL(testChatUser)
if err != nil {
t.Error("AuthAvatar.GetAvatarURL should return no error when value present")
} else {
if url != testUrl {
t.Error("AuthAvatar.GetAvatarURL should return correct URL")
}
}
}
func TestGravatarAvatar(t *testing.T) {
var gravatarAvatar GravatarAvatar
user := &chatUser{uniqueID: "abc"}
url, err := gravatarAvatar.GetAvatarURL(user)
if err != nil {
t.Error("GravatarAvatar.GetAvatarURL should not return an error")
}
if url != "https://www.gravatar.com/avatar/abc" {
t.Errorf("GravatarAvatar.GetAvatarURL wrongly returnd %s", url)
}
}
func TestFileSystemAvatar(t *testing.T) {
// make a test avatar file
filename := path.Join("avatars", "abc.jpg")
ioutil.WriteFile(filename, []byte{}, 0777)
defer func() { os.Remove(filename) }()
var fileSystemAvatar FileSystemAvatar
user := &chatUser{uniqueID: "abc"}
client := new(client)
client.userData = map[string]interface{}{"userid": "abc"}
url, err := fileSystemAvatar.GetAvatarURL(user)
if err != nil {
t.Error("FileSystemAvatar.GetAvatarURL should not return an error")
}
if url != "/avatars/abc.jpg" {
t.Errorf("FileSystemAvatar.GetAvatarURL wrongly returned %s", url)
}
}