-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a metric defined as a counter to match all lines, useful for cr…
…eating line count metrics which include all your labels. Found a bug in the the test runner where it didn't fail if the actual error was nil but the test expected an error Added some tests to the counters to test valid configs Signed-off-by: Edward Welch <edward.welch@grafana.com>
- Loading branch information
Showing
5 changed files
with
105 additions
and
16 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
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,62 @@ | ||
package metric | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
counterTestTrue = true | ||
counterTestFalse = false | ||
counterTestVal = "some val" | ||
) | ||
|
||
func Test_validateCounterConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
config CounterConfig | ||
err error | ||
}{ | ||
{"invalid action", | ||
CounterConfig{ | ||
Action: "del", | ||
}, | ||
errors.Errorf(ErrCounterInvalidAction, "del"), | ||
}, | ||
{"invalid counter match all", | ||
CounterConfig{ | ||
MatchAll: &counterTestTrue, | ||
Value: &counterTestVal, | ||
Action: "inc", | ||
}, | ||
errors.New(ErrCounterInvalidMatchAll), | ||
}, | ||
{"valid", | ||
CounterConfig{ | ||
Value: &counterTestVal, | ||
Action: "inc", | ||
}, | ||
nil, | ||
}, | ||
{"valid match all is false", | ||
CounterConfig{ | ||
MatchAll: &counterTestFalse, | ||
Value: &counterTestVal, | ||
Action: "inc", | ||
}, | ||
nil, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := validateCounterConfig(&tt.config) | ||
if ((err != nil) && (err.Error() != tt.err.Error())) || (err == nil && tt.err != nil) { | ||
t.Errorf("Metrics stage validation error, expected error = %v, actual error = %v", tt.err, err) | ||
return | ||
} | ||
}) | ||
} | ||
} |
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