Skip to content

Commit

Permalink
check for no errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeniawhite committed Dec 6, 2023
1 parent f1de9f2 commit 6d06a1e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions libbeat/common/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func TestConvertNestedMapStr(t *testing.T) {

g := NewGenericEventConverter(false)
for i, test := range tests {
g.Convert(test.Input)
errs := g.Convert(test.Input)
assert.Empty(t, errs)
assert.Equal(t, test.Output, test.Input, "Test case %d", i)
}
}
Expand Down Expand Up @@ -195,7 +196,8 @@ func TestConvertNestedStruct(t *testing.T) {

g := NewGenericEventConverter(false)
for i, test := range tests {
g.Convert(test.Input)
errs := g.Convert(test.Input)
assert.Empty(t, errs)
assert.EqualValues(t, test.Output, test.Input, "Test case %v", i)
}
}
Expand Down Expand Up @@ -241,7 +243,8 @@ func TestConvertWithNullEmission(t *testing.T) {

g := NewGenericEventConverter(true)
for i, test := range tests {
g.Convert(test.Input)
errs := g.Convert(test.Input)
assert.Empty(t, errs)
assert.EqualValues(t, test.Output, test.Input, "Test case %v", i)
}
}
Expand Down Expand Up @@ -426,31 +429,35 @@ func TestNormalizeTime(t *testing.T) {
func BenchmarkConvertToGenericEventNetString(b *testing.B) {
g := NewGenericEventConverter(false)
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": NetString("hola")})
errs := g.Convert(mapstr.M{"key": NetString("hola")})
assert.Empty(b, errs)
}
}

// Uses reflection.
func BenchmarkConvertToGenericEventMapStringString(b *testing.B) {
g := NewGenericEventConverter(false)
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": map[string]string{"greeting": "hola"}})
errs := g.Convert(mapstr.M{"key": map[string]string{"greeting": "hola"}})
assert.Empty(b, errs)
}
}

// Uses recursion to step into the nested mapstr.M.
func BenchmarkConvertToGenericEventMapStr(b *testing.B) {
g := NewGenericEventConverter(false)
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": map[string]interface{}{"greeting": "hola"}})
errs := g.Convert(mapstr.M{"key": map[string]interface{}{"greeting": "hola"}})
assert.Empty(b, errs)
}
}

// No reflection required.
func BenchmarkConvertToGenericEventStringSlice(b *testing.B) {
g := NewGenericEventConverter(false)
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": []string{"foo", "bar"}})
errs := g.Convert(mapstr.M{"key": []string{"foo", "bar"}})
assert.Empty(b, errs)
}
}

Expand All @@ -459,7 +466,8 @@ func BenchmarkConvertToGenericEventCustomStringSlice(b *testing.B) {
g := NewGenericEventConverter(false)
type myString string
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": []myString{"foo", "bar"}})
errs := g.Convert(mapstr.M{"key": []myString{"foo", "bar"}})
assert.Empty(b, errs)
}
}

Expand All @@ -468,7 +476,8 @@ func BenchmarkConvertToGenericEventStringPointer(b *testing.B) {
g := NewGenericEventConverter(false)
val := "foo"
for i := 0; i < b.N; i++ {
g.Convert(mapstr.M{"key": &val})
errs := g.Convert(mapstr.M{"key": &val})
assert.Empty(b, errs)
}
}
func TestDeDotJSON(t *testing.T) {
Expand Down

0 comments on commit 6d06a1e

Please sign in to comment.