2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommenterSessionUpdateBasics(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
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
|
|
|
if err := commenterSessionUpdate(commenterToken, "temp-commenter-hex"); err != nil {
|
|
|
|
t.Errorf("unexpected error updating commenter session: %v", err)
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
2018-06-20 11:41:11 +08:00
|
|
|
|
|
|
|
statement := `
|
|
|
|
SELECT commenterHex
|
|
|
|
FROM commenterSessions
|
|
|
|
WHERE commenterToken = $1;
|
|
|
|
`
|
|
|
|
row := db.QueryRow(statement, commenterToken)
|
|
|
|
|
|
|
|
var commenterHex string
|
|
|
|
if err := row.Scan(&commenterHex); err != nil {
|
|
|
|
t.Errorf("error scanning commenterHex: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if commenterHex != "temp-commenter-hex" {
|
|
|
|
t.Errorf("expected commenterHex=temp-commenter-hex got commenterHex=%s", commenterHex)
|
|
|
|
return
|
|
|
|
}
|
2018-05-27 22:40:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommenterSessionUpdateEmpty(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
|
|
|
if err := commenterSessionUpdate("", "temp-commenter-hex"); err == nil {
|
2018-06-20 11:29:55 +08:00
|
|
|
t.Errorf("expected error not found when updating with empty commenterToken")
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|