forked from robdelacruz/newsboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nb_test.go
53 lines (47 loc) · 1.36 KB
/
nb_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
package main
import (
"database/sql"
"fmt"
"log"
"os"
"testing"
)
func TestSQL(t *testing.T) {
// Exit if specified notes file doesn't exist.
dbfile := "news.db"
if !fileExists(dbfile) {
s := fmt.Sprintf(`Newboard file '%s' doesn't exist. Create one using:
nb -i <newsboard_file>
`, dbfile)
fmt.Printf(s)
os.Exit(1)
}
registerSqliteFuncs()
db, err := sql.Open("sqlite3_custom", dbfile)
if err != nil {
fmt.Printf("Error opening '%s' (%s)\n", dbfile, err)
os.Exit(1)
}
fmt.Printf("Test custom sqlite funcs.\n")
s := "SELECT entry_id, pow(entry_id, 2.0), randint(10), seconds_since_epoch(createdt), seconds_since_time(createdt), hours_since_time(createdt), calculate_points(entry_id, createdt) FROM entry ORDER BY entry_id"
rows, err := db.Query(s)
if err != nil {
log.Fatal(err)
return
}
for rows.Next() {
var npow int
var randomnum int
var entryid int64
var secsEpoch, secsTime, hoursTime int64
var points float64
rows.Scan(&entryid, &npow, &randomnum, &secsEpoch, &secsTime, &hoursTime, &points)
fmt.Printf("%d, %d, %d, %d, %d, %d, points=%f\n", entryid, npow, randomnum, secsEpoch, secsTime, hoursTime, points)
}
}
func TestCrypto(t *testing.T) {
ciphertext := encrypt([]byte("Hello World"), "password")
fmt.Printf("Encrypted: %x\n", ciphertext)
plaintext := decrypt(ciphertext, "password")
fmt.Printf("Decrypted: %s\n", plaintext)
}