@@ -188,29 +188,30 @@ func Test_MarshalAsMsgpack(t *testing.T) {
188188}
189189
190190func Test_SubSecondPrecision (t * testing.T ) {
191- f := & Fluent {Config : Config {SubSecondPrecision : true }, reconnecting : false }
192-
193- conn := & Conn {}
194- f .conn = conn
191+ // Setup the test subject
192+ fluent := & Fluent {
193+ Config : Config {
194+ SubSecondPrecision : true ,
195+ },
196+ reconnecting : false ,
197+ }
198+ fluent .conn = & Conn {}
195199
196- tag := "tag"
197- var data = map [string ]string {
198- "foo" : "bar" ,
199- "hoge" : "hoge" }
200- tm := time .Unix (1267867237 , 0 )
201- result , err := f .EncodeData (tag , tm , data )
200+ // Exercise the test subject
201+ timestamp := time .Unix (1267867237 , 0 )
202+ encodedData , err := fluent .EncodeData ("tag" , timestamp , map [string ]string {
203+ "foo" : "bar" ,
204+ })
202205
206+ // Assert no encoding errors and that the timestamp has been encoded into
207+ // the message as expected.
203208 if err != nil {
204209 t .Error (err )
205210 }
206- actual := string (result )
207211
208- // map entries are disordered in golang
209- expected1 := "\x94 \xA3 tag\xC7 \x08 \x00 K\x92 \u001E e\x00 \x00 \x00 \x00 \x82 \xA3 foo\xA3 bar\xA4 hoge\xA4 hoge\xC0 "
210- expected2 := "\x94 \xA3 tag\xC7 \x08 \x00 K\x92 \u001E e\x00 \x00 \x00 \x00 \x82 \xA4 hoge\xA4 hoge\xA3 foo\xA3 bar\xC0 "
211- if actual != expected1 && actual != expected2 {
212- t .Errorf ("got %x,\n except %x\n or %x" , actual , expected1 , expected2 )
213- }
212+ expected := "\x94 \xA3 tag\xC7 \x08 \x00 K\x92 \u001E e\x00 \x00 \x00 \x00 \x81 \xA3 foo\xA3 bar\xC0 "
213+ actual := string (encodedData )
214+ assert .Equal (t , expected , actual )
214215}
215216
216217func Test_MarshalAsJSON (t * testing.T ) {
0 commit comments