sort map keys when generating asserts (#2494)
* sort map keys when generating asserts
This commit is contained in:
parent
b2a6eb92bf
commit
3cd4847093
|
@ -232,30 +232,34 @@ func (p *ParserAssert) AutoGenParserAssert() string {
|
||||||
if !result.Success {
|
if !result.Success {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for pkey, pval := range result.Evt.Parsed {
|
for _, pkey := range sortedMapKeys(result.Evt.Parsed) {
|
||||||
|
pval := result.Evt.Parsed[pkey]
|
||||||
if pval == "" {
|
if pval == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Parsed["%s"] == "%s"`+"\n", stage, parser, pidx, pkey, Escape(pval))
|
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Parsed["%s"] == "%s"`+"\n", stage, parser, pidx, pkey, Escape(pval))
|
||||||
}
|
}
|
||||||
for mkey, mval := range result.Evt.Meta {
|
for _, mkey := range sortedMapKeys(result.Evt.Meta) {
|
||||||
|
mval := result.Evt.Meta[mkey]
|
||||||
if mval == "" {
|
if mval == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Meta["%s"] == "%s"`+"\n", stage, parser, pidx, mkey, Escape(mval))
|
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Meta["%s"] == "%s"`+"\n", stage, parser, pidx, mkey, Escape(mval))
|
||||||
}
|
}
|
||||||
for ekey, eval := range result.Evt.Enriched {
|
for _, ekey := range sortedMapKeys(result.Evt.Enriched) {
|
||||||
|
eval := result.Evt.Enriched[ekey]
|
||||||
if eval == "" {
|
if eval == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Enriched["%s"] == "%s"`+"\n", stage, parser, pidx, ekey, Escape(eval))
|
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Enriched["%s"] == "%s"`+"\n", stage, parser, pidx, ekey, Escape(eval))
|
||||||
}
|
}
|
||||||
for ekey, eval := range result.Evt.Unmarshaled {
|
for _, ukey := range sortedMapKeys(result.Evt.Unmarshaled) {
|
||||||
if eval == "" {
|
uval := result.Evt.Unmarshaled[ukey]
|
||||||
|
if uval == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
base := fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Unmarshaled["%s"]`, stage, parser, pidx, ekey)
|
base := fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Unmarshaled["%s"]`, stage, parser, pidx, ukey)
|
||||||
for _, line := range p.buildUnmarshaledAssert(base, eval) {
|
for _, line := range p.buildUnmarshaledAssert(base, uval) {
|
||||||
ret += line
|
ret += line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,18 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func sortedMapKeys[V any](m map[string]V) []string {
|
||||||
|
keys := make([]string, 0, len(m))
|
||||||
|
for k := range m {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
func Copy(src string, dst string) error {
|
func Copy(src string, dst string) error {
|
||||||
content, err := os.ReadFile(src)
|
content, err := os.ReadFile(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue