Skip to content

Commit

Permalink
returning list with unsupported hints and fixing test to check those
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas committed Mar 7, 2024
1 parent 1795076 commit 9306516
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions utils/hints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestGenerateHints(t *testing.T) {
processors = "processors"
)

var allSupportedHints = []string{"enabled", "module", integration, datastreams, host, period, timeout, metricspath, username, password, stream, processors}
var allSupportedHints = []string{"enabled", "module", integration, datastreams, host, period, timeout, metricspath, username, password, stream, processors, "multiline", "json", "disable"}

tests := []struct {
annotations map[string]string
Expand All @@ -90,6 +90,7 @@ func TestGenerateHints(t *testing.T) {
"co.elastic.metrics/period": "10s",
"co.elastic.metrics.foobar/period": "15s",
"co.elastic.metrics.foobar1/period": "15s",
"co.elastic.hints.steam": "stdout", // On purpose this added with typo
"not.to.include": "true",
},
result: mapstr.M{
Expand All @@ -114,15 +115,15 @@ func TestGenerateHints(t *testing.T) {
// metrics/metrics_path must be found in hints.metrics
{
annotations: map[string]string{
"co.elastic.logs/multiline.pattern": "^test",
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/period": "10s",
"co.elastic.metrics/metrics_path": "/metrics/prometheus",
"co.elastic.metrics/username": "user",
"co.elastic.metrics/password": "pass",
"co.elastic.metrics.foobar/period": "15s",
"co.elastic.metrics.foobar1/periods": "15s",
"not.to.include": "true",
"co.elastic.logs/multiline.pattern": "^test",
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/period": "10s",
"co.elastic.metrics/metrics_path": "/metrics/prometheus",
"co.elastic.metrics/username": "user",
"co.elastic.metrics/password": "pass",
"co.elastic.metrics.foobar/period": "15s",
"co.elastic.metrics.foobar1/period": "15s",
"not.to.include": "true",
},
result: mapstr.M{
"logs": mapstr.M{
Expand Down Expand Up @@ -226,15 +227,21 @@ func TestGenerateHints(t *testing.T) {
},
}

for _, test := range tests {
for key, test := range tests {
annMap := mapstr.M{}
for k, v := range test.annotations {
_, err := annMap.Put(k, v)
if err != nil {
continue
}
}
generateHints, _ := GenerateHints(annMap, "foobar", "co.elastic", allSupportedHints)
generateHints, incorrecthints := GenerateHints(annMap, "foobar", "co.elastic", allSupportedHints)
//Only in test1 we have added co.elastic.hints.steam annotation with a typo error
if key == 1 {
assert.Equal(t, 1, len(incorrecthints)) // We validate how many incorrect hints are provided in test1.
} else {
assert.Equal(t, 0, len(incorrecthints)) // We validate how many incorrect hints are provided in rest of tests
}
assert.Equal(t, test.result, generateHints)
}
}
Expand Down

0 comments on commit 9306516

Please sign in to comment.