2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommenterGetByHexBasics(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
2018-06-11 01:15:56 +08:00
|
|
|
commenterHex, _ := commenterNew("test@example.com", "Test", "undefined", "https://example.com/photo.jpg", "google", "")
|
2018-05-27 22:40:42 +08:00
|
|
|
|
|
|
|
c, err := commenterGetByHex(commenterHex)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error getting commenter by hex: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Name != "Test" {
|
|
|
|
t.Errorf("expected name=Test got name=%s", c.Name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommenterGetByHexEmpty(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
|
|
|
if _, err := commenterGetByHex(""); err == nil {
|
|
|
|
t.Errorf("expected error not found getting commenter with empty hex")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
func TestCommenterGetByCommenterToken(t *testing.T) {
|
2018-05-27 22:40:42 +08:00
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
2018-06-11 01:15:56 +08:00
|
|
|
commenterHex, _ := commenterNew("test@example.com", "Test", "undefined", "https://example.com/photo.jpg", "google", "")
|
2018-05-27 22:40:42 +08:00
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
commenterToken, _ := commenterTokenNew()
|
2018-05-27 22:40:42 +08:00
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
commenterSessionUpdate(commenterToken, commenterHex)
|
2018-05-27 22:40:42 +08:00
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
c, err := commenterGetByCommenterToken(commenterToken)
|
2018-05-27 22:40:42 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error getting commenter by hex: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Name != "Test" {
|
|
|
|
t.Errorf("expected name=Test got name=%s", c.Name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
func TestCommenterGetByCommenterTokenEmpty(t *testing.T) {
|
2018-05-27 22:40:42 +08:00
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
if _, err := commenterGetByCommenterToken(""); err == nil {
|
|
|
|
t.Errorf("expected error not found getting commenter with empty commenterToken")
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-06-08 01:46:17 +08:00
|
|
|
|
|
|
|
func TestCommenterGetByName(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
2018-06-11 01:15:56 +08:00
|
|
|
commenterHex, _ := commenterNew("test@example.com", "Test", "undefined", "https://example.com/photo.jpg", "google", "")
|
2018-06-08 01:46:17 +08:00
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
commenterToken, _ := commenterTokenNew()
|
2018-06-08 01:46:17 +08:00
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
commenterSessionUpdate(commenterToken, commenterHex)
|
2018-06-08 01:46:17 +08:00
|
|
|
|
|
|
|
c, err := commenterGetByEmail("google", "test@example.com")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error getting commenter by hex: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Name != "Test" {
|
|
|
|
t.Errorf("expected name=Test got name=%s", c.Name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommenterGetByNameEmpty(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
|
|
|
if _, err := commenterGetByEmail("", ""); err == nil {
|
|
|
|
t.Errorf("expected error not found getting commenter with empty everything")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|