@@ -15,6 +15,8 @@ import (
15
15
16
16
var myAddr = flag .String ("my_addr" , "127.0.0.1:3306" , "MySQL addr" )
17
17
var esAddr = flag .String ("es_addr" , "127.0.0.1:9200" , "Elasticsearch addr" )
18
+ var dateTimeStr = time .Now ().Format (mysql .TimeFormat )
19
+ var dateStr = time .Now ().Format (mysqlDateFormat )
18
20
19
21
func Test (t * testing.T ) {
20
22
TestingT (t )
@@ -36,17 +38,18 @@ func (s *riverTestSuite) SetUpSuite(c *C) {
36
38
37
39
schema := `
38
40
CREATE TABLE IF NOT EXISTS %s (
39
- id INT,
40
- title VARCHAR(256),
41
- content VARCHAR(256),
42
- mylist VARCHAR(256),
43
- mydate INT(10),
44
- tenum ENUM("e1", "e2", "e3"),
45
- tset SET("a", "b", "c"),
46
- tbit BIT(1) default 1,
47
- tdatetime DATETIME DEFAULT NULL,
48
- ip INT UNSIGNED DEFAULT 0,
49
- PRIMARY KEY(id)) ENGINE=INNODB;
41
+ id INT,
42
+ title VARCHAR(256),
43
+ content VARCHAR(256),
44
+ mylist VARCHAR(256),
45
+ mydate INT(10),
46
+ tenum ENUM("e1", "e2", "e3"),
47
+ tset SET("a", "b", "c"),
48
+ tbit BIT(1) default 1,
49
+ tdatetime DATETIME DEFAULT NULL,
50
+ tdate DATE DEFAULT NULL,
51
+ ip INT UNSIGNED DEFAULT 0,
52
+ PRIMARY KEY(id)) ENGINE=INNODB;
50
53
`
51
54
52
55
schemaJSON := `
@@ -223,8 +226,10 @@ func (s *riverTestSuite) testPrepareData(c *C) {
223
226
s .testExecute (c , fmt .Sprintf ("INSERT INTO %s (id, title, content, tenum, tset) VALUES (?, ?, ?, ?, ?)" , table ), 5 + i , "abc" , "hello" , "e1" , "a,b,c" )
224
227
}
225
228
226
- datetime := time .Now ().Format (mysql .TimeFormat )
227
- s .testExecute (c , "INSERT INTO test_river (id, title, content, tenum, tset, tdatetime, mydate) VALUES (?, ?, ?, ?, ?, ?, ?)" , 16 , "test datetime" , "hello go 16" , "e1" , "a,b" , datetime , 1458131094 )
229
+ s .testExecute (c , "INSERT INTO test_river (id, title, content, tenum, tset, tdatetime, mydate, tdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , 16 , "test datetime" , "hello go 16" , "e1" , "a,b" , dateTimeStr , 1458131094 , dateStr )
230
+
231
+ s .testExecute (c , "SET sql_mode = '';" ) // clear sql_mode to allow empty dates
232
+ s .testExecute (c , "INSERT INTO test_river (id, title, content, tenum, tset, tdatetime, mydate, tdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , 20 , "test empty datetime" , "date test 20" , "e1" , "a,b" , "0000-00-00 00:00:00" , 0 , "0000-00-00" )
228
233
229
234
// test ip
230
235
s .testExecute (c , "INSERT test_river (id, ip) VALUES (?, ?)" , 17 , 0 )
@@ -248,6 +253,7 @@ func (s *riverTestSuite) testElasticMapping(c *C) *elastic.MappingResponse {
248
253
c .Assert (err , IsNil )
249
254
250
255
c .Assert (r .Mapping [index ].Mappings [docType ].Properties ["tdatetime" ].Type , Equals , "date" )
256
+ c .Assert (r .Mapping [index ].Mappings [docType ].Properties ["tdate" ].Type , Equals , "date" )
251
257
c .Assert (r .Mapping [index ].Mappings [docType ].Properties ["mydate" ].Type , Equals , "date" )
252
258
return r
253
259
}
@@ -359,6 +365,17 @@ func (s *riverTestSuite) TestRiver(c *C) {
359
365
c .Assert (r .Source ["es_title" ], Equals , "hello" )
360
366
}
361
367
368
+ r = s .testElasticGet (c , "16" )
369
+ c .Assert (r .Found , IsTrue )
370
+ tdt , _ := time .Parse (time .RFC3339 , r .Source ["tdatetime" ].(string ))
371
+ c .Assert (tdt .Format (mysql .TimeFormat ), Equals , dateTimeStr )
372
+ c .Assert (r .Source ["tdate" ], Equals , dateStr )
373
+
374
+ r = s .testElasticGet (c , "20" )
375
+ c .Assert (r .Found , IsTrue )
376
+ c .Assert (r .Source ["tdate" ], Equals , nil )
377
+ c .Assert (r .Source ["tdatetime" ], Equals , nil )
378
+
362
379
// test ip
363
380
r = s .testElasticGet (c , "17" )
364
381
c .Assert (r .Found , IsTrue )
0 commit comments