answer/pkg/gravatar/gravatar_test.go

73 lines
1.7 KiB
Go
Raw Permalink Normal View History

2022-10-28 10:50:36 +08:00
package gravatar
import (
"github.com/answerdev/answer/internal/base/constant"
2022-10-28 10:50:36 +08:00
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetAvatarURL(t *testing.T) {
type args struct {
email string
}
tests := []struct {
name string
args args
want string
}{
{
name: "answer@answer.com",
args: args{email: "answer@answer.com"},
want: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, GetAvatarURL(constant.DefaultGravatarBaseURL, tt.args.email))
2022-10-28 10:50:36 +08:00
})
}
}
func TestResize(t *testing.T) {
type args struct {
originalAvatarURL string
sizePixel int
}
tests := []struct {
name string
args args
wantResizedAvatarURL string
}{
{
name: "original url",
args: args{
originalAvatarURL: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7",
sizePixel: 128,
},
2022-10-28 11:01:42 +08:00
wantResizedAvatarURL: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7?s=128",
2022-10-28 10:50:36 +08:00
},
{
name: "already resized url",
args: args{
2022-10-28 11:01:42 +08:00
originalAvatarURL: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7?s=128",
2022-10-28 10:50:36 +08:00
sizePixel: 64,
},
2022-10-28 11:01:42 +08:00
wantResizedAvatarURL: "https://www.gravatar.com/avatar/b2be4e4438f08a5e885be8de5f41fdd7?s=64",
2022-10-28 10:50:36 +08:00
},
{
name: "empty url",
args: args{
originalAvatarURL: "",
sizePixel: 64,
},
wantResizedAvatarURL: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.wantResizedAvatarURL, Resize(tt.args.originalAvatarURL, tt.args.sizePixel), "Resize(%v, %v)", tt.args.originalAvatarURL, tt.args.sizePixel)
})
}
}