-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Osquerybeat: Fix missing result values when the value can not be conv…
…erted into expected type (#33587)
- Loading branch information
1 parent
2882bf6
commit 466b95d
Showing
2 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package osqdcli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestResolveHitTypes(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
hit, colTypes map[string]string | ||
res map[string]interface{} | ||
}{ | ||
{ | ||
name: "empty", | ||
res: map[string]interface{}{}, | ||
}, | ||
{ | ||
name: "resolvable", | ||
hit: map[string]string{ | ||
"pid": "5551", | ||
"pid_int": "5552", | ||
"pid_uint": "5553", | ||
"pid_text": "5543", | ||
"foo": "bar", | ||
}, | ||
colTypes: map[string]string{ | ||
"pid": "BIGINT", | ||
"pid_int": "INTEGER", | ||
"pid_uint": "UNSIGNED_BIGINT", | ||
"pid_text": "TEXT", | ||
}, | ||
res: map[string]interface{}{ | ||
"pid": int64(5551), | ||
"pid_int": int64(5552), | ||
"pid_uint": uint64(5553), | ||
"pid_text": "5543", | ||
"foo": "bar", | ||
}, | ||
}, | ||
{ | ||
// Should preserve the field if it can not be parsed into the type | ||
name: "wrong type", | ||
hit: map[string]string{ | ||
"data": "0,22,137,138,29754,49154,49155", | ||
"foo": "bar", | ||
}, | ||
colTypes: map[string]string{"data": "BIGINT"}, | ||
res: map[string]interface{}{ | ||
"data": "0,22,137,138,29754,49154,49155", | ||
"foo": "bar", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
res := resolveHitTypes(tc.hit, tc.colTypes) | ||
diff := cmp.Diff(tc.res, res) | ||
if diff != "" { | ||
t.Fatal(diff) | ||
} | ||
}) | ||
} | ||
} |