Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add [defaults] placeholder support to collectors.enabled
- Loading branch information
Showing
2 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
type expansionTestCase struct { | ||
input string | ||
expectedOutput []string | ||
} | ||
|
||
func TestExpandEnabled(t *testing.T) { | ||
expansionTests := []expansionTestCase{ | ||
{"", []string{}}, | ||
// Default case | ||
{"cs,os", []string{"cs", "os"}}, | ||
// Placeholder expansion | ||
{defaultCollectorsPlaceholder, strings.Split(defaultCollectors, ",")}, | ||
// De-duplication | ||
{"cs,cs", []string{"cs"}}, | ||
// De-duplicate placeholder | ||
{defaultCollectorsPlaceholder + "," + defaultCollectorsPlaceholder, strings.Split(defaultCollectors, ",")}, | ||
// Composite case | ||
{"foo," + defaultCollectorsPlaceholder + ",bar", append(strings.Split(defaultCollectors, ","), "foo", "bar")}, | ||
} | ||
|
||
for _, testCase := range expansionTests { | ||
output := expandEnabledCollectors(testCase.input) | ||
sort.Strings(output) | ||
|
||
success := true | ||
if len(output) != len(testCase.expectedOutput) { | ||
success = false | ||
} else { | ||
sort.Strings(testCase.expectedOutput) | ||
for idx := range output { | ||
if output[idx] != testCase.expectedOutput[idx] { | ||
success = false | ||
break | ||
} | ||
} | ||
} | ||
if !success { | ||
t.Error("For", testCase.input, "expected", testCase.expectedOutput, "got", output) | ||
} | ||
} | ||
} |