Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Headers definition from byte to int8 for KafkaRecord #506

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion events/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ type KafkaRecord struct {
TimestampType string `json:"timestampType"`
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
Headers []map[string][]byte `json:"headers"`
Headers []map[string][]int8 `json:"headers"`
}
13 changes: 11 additions & 2 deletions events/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func TestKafkaEventMarshaling(t *testing.T) {
t.Errorf("could not unmarshal event. details: %v", err)
}

// expected values for header
var headerValues [5]int8
headerValues[0] = 118
headerValues[1] = -36
headerValues[2] = 0
headerValues[3] = 127
headerValues[4] = -128

assert.Equal(t, inputEvent.BootstrapServers, "b-2.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092,b-1.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092")
assert.Equal(t, inputEvent.EventSource, "aws:kafka")
assert.Equal(t, inputEvent.EventSourceARN, "arn:aws:kafka:us-west-2:012345678901:cluster/ExampleMSKCluster/e9f754c6-d29a-4430-a7db-958a19fd2c54-4")
Expand All @@ -33,8 +41,9 @@ func TestKafkaEventMarshaling(t *testing.T) {
for _, header := range record.Headers {
for key, value := range header {
assert.Equal(t, key, "headerKey")
headerValue := string(value)
assert.Equal(t, headerValue, "headerValue")
for i, headerValue := range value {
assert.Equal(t, headerValue, headerValues[i])
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion events/testdata/kafka-event.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
"value": "OGQ1NTk2YjQtMTgxMy00MjM4LWIyNGItNmRhZDhlM2QxYzBj",
"headers": [
{
"headerKey": "aGVhZGVyVmFsdWU="
"headerKey": [
118,
-36,
0,
127,
-128
]
}
]
}
Expand Down