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
|
package main
import (
"database/sql"
"io/ioutil"
"net/http"
"os"
"testing"
)
var (
db *sql.DB
db_path string
)
func TestInitDB(t *testing.T) {
tmpDB, _ := ioutil.TempFile("", "tmp-*.db")
db_path = tmpDB.Name()
os.Remove(db_path)
db = initDB(db_path)
}
func TestAddArchived(t *testing.T) {
m := Message{
URL: "http://example.com/",
Author: "000000000000000000",
Guild: "000000000000000000",
Channel: "000000000000000000",
}
addArchived(db, &m, 200)
}
func TestIsCached(t *testing.T) {
url := "http://example.com/"
cached, status_code := isCached(db, url)
if status_code != http.StatusOK || cached != true {
t.Errorf("Received %t, %d; wanted %t, %d", cached, status_code, true,
http.StatusOK)
}
}
func TestDBCleanup(t *testing.T) {
os.Remove(db_path)
}
|