Skip to content

Commit 02b5c51

Browse files
author
Jeff Wolski
committed
Cleaned up the sub-second test
1 parent 351160d commit 02b5c51

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

fluent/fluent_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,29 +188,30 @@ func Test_MarshalAsMsgpack(t *testing.T) {
188188
}
189189

190190
func 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\xA3tag\xC7\x08\x00K\x92\u001Ee\x00\x00\x00\x00\x82\xA3foo\xA3bar\xA4hoge\xA4hoge\xC0"
210-
expected2 := "\x94\xA3tag\xC7\x08\x00K\x92\u001Ee\x00\x00\x00\x00\x82\xA4hoge\xA4hoge\xA3foo\xA3bar\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\xA3tag\xC7\x08\x00K\x92\u001Ee\x00\x00\x00\x00\x81\xA3foo\xA3bar\xC0"
213+
actual := string(encodedData)
214+
assert.Equal(t, expected, actual)
214215
}
215216

216217
func Test_MarshalAsJSON(t *testing.T) {

0 commit comments

Comments
 (0)