Skip to content

Commit 202d0da

Browse files
authored
Merge pull request #22 from calyptia/extra-case-157
Add UUID as a expression identifier.
2 parents 6cb18a4 + 4bad96e commit 202d0da

File tree

2 files changed

+67
-37
lines changed

2 files changed

+67
-37
lines changed

parser.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
{"Address", `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`},
2626
{"Unit", `[-+]?(\d*\.)?\d+([kKmMgG])`},
2727
{"Float", `[-+]?\d*\.\d+`},
28+
{"UUID", `^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}`},
2829
{"Number", `[-+]?\d+`},
2930
{"Ident", `[a-zA-Z_\.\*\-0-9]+`},
3031
{"List", `([a-zA-Z_\.\*\-0-9\/]+ )+[a-zA-Z_\.\*\-0-9\/]+`},
@@ -77,6 +78,7 @@ type Field struct {
7778
type Value struct {
7879
JsonObject *string `@JsonObject`
7980
TemplateVariable *string `| @TemplateVariable`
81+
Uuid *string `| @UUID`
8082
Address *string `| @Address`
8183
DateTime *string `| @DateTime`
8284
Date *string `| @Date`

parser_test.go

+65-37
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func TestNewConfigFromBytes(t *testing.T) {
612612
Host api.coralogix.com
613613
Port 443
614614
URI /logs/rest/singles
615-
Header private_key Private_Key-Super-Complex-testing-123
615+
Header private_key 0886464e-ccba-ff8b-83ff-4fa9c3cc0f72
616616
Format json_lines
617617
Compress On
618618
`),
@@ -662,6 +662,70 @@ func TestNewConfigFromBytes(t *testing.T) {
662662
},
663663
expectedError: false,
664664
},
665+
{
666+
name: "test valid large configuration bug 157 - 2nd case",
667+
config: []byte(`[INPUT]
668+
Name forward
669+
Host 0.0.0.0
670+
Port 24284
671+
672+
[OUTPUT]
673+
Name http
674+
Match dummy.*
675+
Host api.coralogix.com
676+
Port 443
677+
URI /logs/rest/singles
678+
Header private_key EXPLICITLY-LONG-KEY-12345
679+
Format json_lines
680+
Compress On
681+
`),
682+
expected: Config{
683+
Sections: []ConfigSection{{
684+
Type: InputSection,
685+
Fields: []Field{
686+
{Key: "Name", Values: []Value{{
687+
String: stringPtr("forward"),
688+
}}},
689+
{Key: "Host", Values: []Value{{
690+
String: stringPtr("0.0.0.0"),
691+
}}},
692+
{Key: "Port", Values: []Value{{
693+
String: stringPtr("24284"),
694+
}}},
695+
},
696+
}, {
697+
Type: OutputSection,
698+
Fields: []Field{
699+
{Key: "Name", Values: []Value{{
700+
String: stringPtr("http"),
701+
}}},
702+
{Key: "Match", Values: []Value{{
703+
String: stringPtr("dummy.*"),
704+
}}},
705+
{Key: "Host", Values: []Value{{
706+
String: stringPtr("api.coralogix.com"),
707+
}}},
708+
{Key: "Port", Values: []Value{{
709+
String: stringPtr("443"),
710+
}}},
711+
{Key: "URI", Values: []Value{{
712+
String: stringPtr("/logs/rest/singles"),
713+
}}},
714+
{Key: "Header", Values: []Value{{
715+
String: stringPtr("private_key EXPLICITLY-LONG-KEY-12345"),
716+
}}},
717+
{Key: "Format", Values: []Value{{
718+
String: stringPtr("json_lines"),
719+
}}},
720+
{Key: "Compress", Values: []Value{{
721+
String: stringPtr("On"),
722+
}}},
723+
},
724+
}},
725+
},
726+
expectedError: false,
727+
},
728+
665729
{
666730
name: "test valid larger configuration",
667731
config: []byte(`[INPUT]
@@ -831,9 +895,6 @@ func TestNewConfigFromBytes(t *testing.T) {
831895
},
832896
}
833897

834-
//stripIndentation := regexp.MustCompile("\n[\t]+")
835-
//stripMultipleSpaces := regexp.MustCompile(`[\ ]{2,}`)
836-
837898
for _, tc := range tt {
838899
t.Run(tc.name, func(t *testing.T) {
839900
cfg, err := ParseINI(tc.config)
@@ -859,40 +920,7 @@ func TestNewConfigFromBytes(t *testing.T) {
859920
t.Errorf("section[%d] wants %v != got %v", idx, want, got)
860921
return
861922
}
862-
863-
/*
864-
for fidx, field := range section.Fields {
865-
if want, got := len(field.Values), len(cfg.Sections[idx].Fields[fidx].Values); want != got {
866-
t.Errorf("section[%d].fields[%s:%d] %d != got %d", idx, field.Key, fidx, want, got)
867-
return
868-
}
869-
for vidx, value := range cfg.Sections[idx].Fields[fidx].Values {
870-
if !value.Equals(field.Values[vidx]) {
871-
t.Errorf("unexpected value section[%d].fields[%s]", idx, field.Key)
872-
return
873-
}
874-
}
875-
}
876-
*/
877923
}
878-
879-
/*
880-
config := stripIndentation.ReplaceAll(tc.config, []byte("\n"))
881-
config = stripMultipleSpaces.ReplaceAll(config, []byte(" "))
882-
883-
if ini, err := cfg.DumpINI(); err != nil {
884-
t.Error(err)
885-
return
886-
} else {
887-
ini = stripIndentation.ReplaceAll(ini, []byte("\n"))
888-
ini = stripMultipleSpaces.ReplaceAll(ini, []byte(""))
889-
if !bytes.Equal(ini, config) {
890-
fmt.Printf("\n'%s'\n != \n'%s'\n", string(config), string(ini))
891-
t.Errorf("unable to reconstitute INI")
892-
}
893-
return
894-
}
895-
*/
896924
})
897925
}
898926
}

0 commit comments

Comments
 (0)