@@ -169,6 +169,7 @@ func TestParseAndFormatValue(t *testing.T) {
169169 {time .UnixDate , "\" Fri Jul 21 08:15:27 +0100 2017\" " },
170170 {time .RFC3339 , "\" 2017-07-21T08:15:27+01:00\" " },
171171 {time .StampNano , "\" Jul 21 08:15:27.000000000\" " },
172+ {"$unix" , "\" 1500621327\" " },
172173 }
173174 for _ , testItem := range parseAndFormatTests {
174175 actual , _ := parseAndFormatValue (inputFormat , testItem .outputFormat , inputTimestamp )
@@ -179,3 +180,27 @@ func TestParseAndFormatValue(t *testing.T) {
179180 }
180181 }
181182}
183+
184+ func TestParseAndFormatValueOutputUnix (t * testing.T ) {
185+ parseAndFormatTests := []struct {
186+ inputFormat string
187+ inputTimestamp string
188+ expectedOutput string
189+ }{
190+ // test against a sampling of common formats
191+ {"2006-01-02T15:04:05-0700" , "2017-07-21T08:15:27+0100" , "\" 1500621327\" " },
192+ {"January _2, 2006" , "July 21, 2017" , "\" 1500595200\" " },
193+ {time .ANSIC , "Fri Jul 21 08:15:27 2017" , "\" 1500624927\" " },
194+ {time .UnixDate , "Fri Jul 21 08:15:27 GMT 2017" , "\" 1500624927\" " },
195+ {time .RFC3339 , "2017-07-21T08:15:27+01:00" , "\" 1500621327\" " },
196+ {"$unix" , "1500621327" , "\" 1500621327\" " },
197+ }
198+ for _ , testItem := range parseAndFormatTests {
199+ actual , _ := parseAndFormatValue (testItem .inputFormat , "$unix" , testItem .inputTimestamp )
200+ if actual != testItem .expectedOutput {
201+ t .Error ("Error data does not match expectation." , testItem .inputFormat )
202+ t .Log ("Expected: " , testItem .expectedOutput )
203+ t .Log ("Actual: " , actual )
204+ }
205+ }
206+ }
0 commit comments