chore(parsers.avro): Add unit-test for enum (#16260)

This commit is contained in:
Sven Rebhan 2024-12-05 17:36:47 +01:00 committed by GitHub
parent 7dc0e18223
commit bec49c2ebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
52 changed files with 77 additions and 28 deletions

View File

@ -17,8 +17,8 @@ import (
)
func TestCases(t *testing.T) {
// Get all directories in testdata
folders, err := os.ReadDir("testdata")
// Get all test-case directories
folders, err := os.ReadDir("testcases")
require.NoError(t, err)
// Make sure testdata contains data
require.NotEmpty(t, folders)
@ -30,7 +30,7 @@ func TestCases(t *testing.T) {
for _, f := range folders {
fname := f.Name()
testdataPath := filepath.Join("testdata", fname)
testdataPath := filepath.Join("testcases", fname)
configFilename := filepath.Join(testdataPath, "telegraf.conf")
expectedFilename := filepath.Join(testdataPath, "expected.out")
expectedErrorFilename := filepath.Join(testdataPath, "expected.err")
@ -110,7 +110,7 @@ func BenchmarkParsing(b *testing.B) {
}
require.NoError(b, plugin.Init())
benchmarkData, err := os.ReadFile(filepath.Join("testdata", "benchmark", "message.json"))
benchmarkData, err := os.ReadFile(filepath.Join("testcases", "benchmark", "message.json"))
require.NoError(b, err)
b.ResetTimer()
@ -131,7 +131,7 @@ func TestBenchmarkDataBinary(t *testing.T) {
}
require.NoError(t, plugin.Init())
benchmarkDir := filepath.Join("testdata", "benchmark")
benchmarkDir := filepath.Join("testcases", "benchmark")
// Read the expected valued from file
parser := &influx.Parser{}
@ -167,7 +167,7 @@ func BenchmarkParsingBinary(b *testing.B) {
require.NoError(b, plugin.Init())
// Re-encode the benchmark data from JSON to binary format
jsonData, err := os.ReadFile(filepath.Join("testdata", "benchmark", "message.json"))
jsonData, err := os.ReadFile(filepath.Join("testcases", "benchmark", "message.json"))
require.NoError(b, err)
codec, err := goavro.NewCodec(benchmarkSchema)
require.NoError(b, err)

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/bad-timestamp-format/message.avro"]
files = ["./testcases/bad-timestamp-format/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
@ -26,4 +26,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/benchmark/message.json"]
files = ["./testcases/benchmark/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/config-both/message.avro"]
files = ["./testcases/config-both/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
@ -25,4 +25,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/config-neither/message.avro"]
files = ["./testcases/config-neither/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
avro_tags = [ "tag" ]

View File

@ -0,0 +1 @@
sensors,name=temperature value_int=42i,status="OK"

View File

@ -0,0 +1,7 @@
{
"name": "temperature",
"value": {
"int": 42
},
"status": "OK"
}

View File

@ -0,0 +1,41 @@
[[ inputs.file ]]
files = ["./testcases/enum/message.json"]
data_format = "avro"
avro_format = "json"
avro_measurement = "sensors"
avro_tags = ["name"]
avro_fields = ["value", "status"]
avro_field_separator = "_"
avro_schema = '''
{
"type": "record",
"name": "Metric",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "value",
"type": [
"null",
"int",
"string"
]
},
{
"name": "status",
"type": {
"type": "enum",
"name": "Status",
"symbols": [
"UNKNOWN",
"OK",
"FAILURE"
]
}
}
]
}
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/json-array/message.json"]
files = ["./testcases/json-array/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/json-format/message.json"]
files = ["./testcases/json-format/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/measurement_name_from_message/message.avro"]
files = ["./testcases/measurement_name_from_message/message.avro"]
data_format = "avro"
avro_measurement_field = "Measurement"
avro_tags = [ "Server" ]
@ -27,4 +27,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/no-timestamp-format/message.avro"]
files = ["./testcases/no-timestamp-format/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
@ -25,4 +25,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/supplied_timestamp/message.avro"]
files = ["./testcases/supplied_timestamp/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
avro_tags = [ "tag" ]
@ -25,4 +25,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/supplied_timestamp_fields_specified/message.avro"]
files = ["./testcases/supplied_timestamp_fields_specified/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
avro_tags = [ "tag" ]
@ -26,4 +26,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/supplied_timestamp_fields_unspecified/message.avro"]
files = ["./testcases/supplied_timestamp_fields_unspecified/message.avro"]
data_format = "avro"
avro_measurement = "measurement"
avro_tags = [ "tag" ]
@ -20,4 +20,4 @@
}
]
}
'''
'''

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-any/message.json"]
files = ["./testcases/union-any/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-array/message.json"]
files = ["./testcases/union-array/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-nullable/message.json"]
files = ["./testcases/union-nullable/message.json"]
data_format = "avro"
avro_format = "json"

View File

@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union/message.json"]
files = ["./testcases/union/message.json"]
data_format = "avro"
avro_format = "json"