Skip to content

Commit 48ce031

Browse files
committed
SCFF-38 added a test regarding the parseCustomMetadata method
1 parent ab93e05 commit 48ce031

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ func (s *SumoLogicAppender) AppendLogs(buffer *SumoBuffer) {
188188
buffer.logEventsInCurrentBuffer++
189189

190190
}
191+
func ParseCustomMetadata(customMetadata string) map[string]string {
192+
cMetadataArray := strings.Split(customMetadata, ",")
193+
customMetadataMap := make(map[string]string)
194+
for i := 0; i < len(cMetadataArray); i++ {
195+
customMetadataMap[strings.Split(cMetadataArray[i], ":")[0]] = strings.Split(cMetadataArray[i], ":")[1]
196+
}
197+
return customMetadataMap
198+
}
191199

192200
func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
193201
if logStringToSend != "" {
@@ -213,9 +221,9 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
213221
}
214222

215223
if s.customMetadata != "" {
216-
cMetadataArray := strings.Split(s.customMetadata, ",")
217-
for i := 0; i < len(cMetadataArray); i++ {
218-
request.Header.Add(strings.Split(cMetadataArray[i], ":")[0], strings.Split(cMetadataArray[i], ":")[1])
224+
customMetadataMap := ParseCustomMetadata(s.customMetadata)
225+
for key, value := range customMetadataMap {
226+
request.Header.Add(key, value)
219227
}
220228
}
221229
//checking the timer before first POST intent

sumoCFFirehose/sumoLogicAppender_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ func TestStringBuilderVerboseLogsTrue(t *testing.T) {
114114
}
115115
finalMessage := StringBuilder(&eventVerboseLogMessage, true)
116116

117-
assert.Contains(t, finalMessage, "source_type", "dsds")
117+
assert.Contains(t, finalMessage, "source_type", "")
118+
119+
}
120+
func TestSendParseCustomMetadata(t *testing.T) {
121+
customMetadata := "Key1:Value1,Key2:Value2,Key3:Value3"
122+
mapCustomMetadata := ParseCustomMetadata(customMetadata)
123+
mapExpected := map[string]string{
124+
"Key1": "Value1",
125+
"Key2": "Value2",
126+
"Key3": "Value3",
127+
}
128+
129+
assert.Equal(t, mapExpected, mapCustomMetadata, "")
118130

119131
}

0 commit comments

Comments
 (0)