/
uidate_test.go
84 lines (76 loc) · 1.7 KB
/
uidate_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package jaws
import (
"errors"
"fmt"
"testing"
"time"
"github.com/linkdata/jaws/what"
)
func TestRequest_Date(t *testing.T) {
th := newTestHelper(t)
nextJid = 0
rq := newTestRequest()
defer rq.Close()
ts := newTestSetter(time.Now())
want := fmt.Sprintf(`<input id="Jid.1" type="date" value="%s">`, ts.Get().Format(ISO8601))
rq.Date(ts)
if got := rq.BodyString(); got != want {
t.Errorf("Request.Date() = %q, want %q", got, want)
}
val, _ := time.Parse(ISO8601, "1970-02-03")
rq.inCh <- wsMsg{Data: val.Format(ISO8601), Jid: 1, What: what.Input}
tmr := time.NewTimer(testTimeout)
defer tmr.Stop()
select {
case <-th.C:
th.Timeout()
case <-ts.setCalled:
}
if ts.Get() != val {
t.Error(ts.Get(), "!=", val)
}
select {
case s := <-rq.outCh:
t.Errorf("%q", s)
default:
}
val = time.Now()
ts.Set(val)
rq.Dirty(ts)
select {
case <-th.C:
th.Timeout()
case msg := <-rq.outCh:
s := msg.Format()
if s != fmt.Sprintf("Value\tJid.1\t\"%s\"\n", val.Format(ISO8601)) {
t.Error("wrong Value")
}
}
if ts.Get() != val {
t.Error("not set")
}
if ts.SetCount() != 1 {
t.Error("SetCount", ts.SetCount())
}
rq.inCh <- wsMsg{Data: "omg", Jid: 1, What: what.Input}
select {
case <-th.C:
th.Timeout()
case msg := <-rq.outCh:
s := msg.Format()
if s != "Alert\t\t\"danger\\nparsing time "omg" as "2006-01-02": cannot parse "omg" as "2006"\"\n" {
t.Errorf("wrong Alert: %q", s)
}
}
ts.err = errors.New("meh")
rq.inCh <- wsMsg{Data: val.Format(ISO8601), Jid: 1, What: what.Input}
select {
case <-th.C:
th.Timeout()
case msg := <-rq.outCh:
s := msg.Format()
if s != "Alert\t\t\"danger\\nmeh\"\n" {
t.Errorf("wrong Alert: %q", s)
}
}
}