forked from Masterminds/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_test.go
36 lines (30 loc) · 822 Bytes
/
date_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
package sprig
import (
"testing"
"time"
)
func TestHtmlDate(t *testing.T) {
t.Skip()
tpl := `{{ htmlDate 0}}`
if err := runt(tpl, "1970-01-01"); err != nil {
t.Error(err)
}
}
func TestAgo(t *testing.T) {
tpl := "{{ ago .Time }}"
if err := runtv(tpl, "2m5s", map[string]interface{}{"Time": time.Now().Add(-125 * time.Second)}); err != nil {
t.Error(err)
}
if err := runtv(tpl, "2h34m17s", map[string]interface{}{"Time": time.Now().Add(-(2*3600 + 34*60 + 17) * time.Second)}); err != nil {
t.Error(err)
}
if err := runtv(tpl, "-4s", map[string]interface{}{"Time": time.Now().Add(5 * time.Second)}); err != nil {
t.Error(err)
}
}
func TestToDate(t *testing.T) {
tpl := `{{toDate "2006-01-02" "2017-12-31" | date "02/01/2006"}}`
if err := runt(tpl, "31/12/2017"); err != nil {
t.Error(err)
}
}