|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"spaceofcheng/services/utils"
|
5
|
5
|
"strings"
|
6
|
6
|
"testing"
|
|
7
|
+ "time"
|
7
|
8
|
)
|
8
|
9
|
|
9
|
10
|
func TestStrSliceIndexOf(t *testing.T) {
|
|
@@ -86,3 +87,32 @@ func TestDecodeBase64NoTail(t *testing.T) {
|
86
|
87
|
}
|
87
|
88
|
}
|
88
|
89
|
}
|
|
90
|
+
|
|
91
|
+func TestGetFiveSeconds(t *testing.T) {
|
|
92
|
+ cases := []map[string]string{
|
|
93
|
+ map[string]string{
|
|
94
|
+ "case": "2018-10-07 13:21:40",
|
|
95
|
+ "expected": "20181007132140",
|
|
96
|
+ },
|
|
97
|
+ map[string]string{
|
|
98
|
+ "case": "2018-10-07 13:21:42",
|
|
99
|
+ "expected": "20181007132140",
|
|
100
|
+ },
|
|
101
|
+ map[string]string{
|
|
102
|
+ "case": "2018-10-07 13:21:45",
|
|
103
|
+ "expected": "20181007132145",
|
|
104
|
+ },
|
|
105
|
+ map[string]string{
|
|
106
|
+ "case": "2018-10-07 13:21:48",
|
|
107
|
+ "expected": "20181007132145",
|
|
108
|
+ },
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ for _, cs := range cases {
|
|
112
|
+ dt, _ := time.Parse("2006-01-02 15:04:05", cs["case"])
|
|
113
|
+ res := utils.GetFiveSeconds(dt)
|
|
114
|
+ if res != cs["expected"] {
|
|
115
|
+ t.Fatalf("TestGetFiveSeconds fail : %s", cs["case"])
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+}
|