-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewthread_test.go
52 lines (46 loc) · 1.21 KB
/
viewthread_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
package main
import (
"net/url"
"testing"
"time"
"codeberg.org/FiskFan1999/gemini"
"github.com/google/go-cmp/cmp"
bolt "go.etcd.io/bbolt"
)
func TestThreadViewHandler(t *testing.T) {
var err error
db, err = bolt.Open(".testing/viewthread1.db", 0600, &bolt.Options{Timeout: time.Second})
if err != nil {
t.Fatal(err.Error())
}
defer db.Close()
url, err := url.Parse("/t/0000000000000001/")
if err != nil {
t.Fatal(err.Error())
}
expect := gemini.ResponseFormat{Status: 20, Mime: "text/gemini", Lines: gemini.Lines{
"# first thread",
"=> /new/post/0000000000000001/ Write comment",
"",
"### user1",
"=> /report/0000000000000001/ Fri, 07 Oct 2022 04:19:19 UTC (click to report)",
"> Hello, this is the first thread.",
"> Goodbye.",
"",
"=> /new/post/0000000000000001/ Write comment",
}}
output := ThreadViewHandler(url, nil)
if !cmp.Equal(expect, output) {
t.Error(cmp.Diff(expect, output))
}
// check for 404
url2, err := url.Parse("/t/1000000000000001/")
if err != nil {
t.Fatal(err.Error())
}
expect2 := gemini.ResponseFormat{Status: 51, Mime: "Not found", Lines: nil}
output2 := ThreadViewHandler(url2, nil)
if !cmp.Equal(expect2, output2) {
t.Error(cmp.Diff(expect2, output2))
}
}