Skip to content

Commit

Permalink
chore(parsers.avro): Add unit-test for enum (influxdata#16260)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Dec 5, 2024
1 parent 7dc0e18 commit bec49c2
Show file tree
Hide file tree
Showing 52 changed files with 77 additions and 28 deletions.
12 changes: 6 additions & 6 deletions plugins/parsers/avro/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -26,4 +26,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/benchmark/message.json"]
files = ["./testcases/benchmark/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/config-both/message.avro"]
files = ["./testcases/config-both/message.avro"]
data_format = "avro"

avro_measurement = "measurement"
Expand All @@ -25,4 +25,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -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" ]
1 change: 1 addition & 0 deletions plugins/parsers/avro/testcases/enum/expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sensors,name=temperature value_int=42i,status="OK"
7 changes: 7 additions & 0 deletions plugins/parsers/avro/testcases/enum/message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "temperature",
"value": {
"int": 42
},
"status": "OK"
}
41 changes: 41 additions & 0 deletions plugins/parsers/avro/testcases/enum/telegraf.conf
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
]
}
'''
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/json-array/message.json"]
files = ["./testcases/json-array/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/json-format/message.json"]
files = ["./testcases/json-format/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -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" ]
Expand Down Expand Up @@ -27,4 +27,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -25,4 +25,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -25,4 +25,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -26,4 +26,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -20,4 +20,4 @@
}
]
}
'''
'''
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-any/message.json"]
files = ["./testcases/union-any/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-array/message.json"]
files = ["./testcases/union-array/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union-nullable/message.json"]
files = ["./testcases/union-nullable/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[ inputs.file ]]
files = ["./testdata/union/message.json"]
files = ["./testcases/union/message.json"]
data_format = "avro"

avro_format = "json"
Expand Down

0 comments on commit bec49c2

Please sign in to comment.