Emmanuel BENOîT
78af496fe9
This PR refactors most of the internals to make them easier to test (and also because the names didn't make sense). It adds unit tests for all internal components. Reviewed-on: #2 Co-authored-by: Emmanuel BENOÎT <tseeker@nocternity.net> Co-committed-by: Emmanuel BENOÎT <tseeker@nocternity.net>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package perfdata // import nocternity.net/gomonop/pkg/perfdata
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestValueCheckValid(t *testing.T) {
|
|
validValues := []string{
|
|
"0", "0.", "0.952", "1", "123", "123.", "123.45", ".1",
|
|
"-0", "-0.", "-0.952", "-1", "-123", "-123.", "-123.45", "-.1",
|
|
}
|
|
|
|
for _, value := range validValues {
|
|
assert.True(t, valueCheck.MatchString(value), "'%s' is a valid value string", value)
|
|
}
|
|
}
|
|
|
|
func TestValueCheckInvalid(t *testing.T) {
|
|
invalidValues := []string{".", "-.", "a", " ", "", "~"}
|
|
|
|
for _, value := range invalidValues {
|
|
assert.False(t, valueCheck.MatchString(value), "'%s' is an invalid value string", value)
|
|
}
|
|
}
|
|
|
|
func TestMinCheckValid(t *testing.T) {
|
|
validValues := []string{
|
|
"0", "0.", "0.952", "1", "123", "123.", "123.45", ".1",
|
|
"-0", "-0.", "-0.952", "-1", "-123", "-123.", "-123.45", "-.1",
|
|
"~",
|
|
}
|
|
|
|
for _, value := range validValues {
|
|
if !rangeMinCheck.MatchString(value) {
|
|
t.Errorf("'%s' is a valid value string", value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMinCheckInvalid(t *testing.T) {
|
|
invalidValues := []string{".", "-.", "a", " ", ""}
|
|
|
|
for _, value := range invalidValues {
|
|
if rangeMinCheck.MatchString(value) {
|
|
t.Errorf("'%s' is an invalid value string", value)
|
|
}
|
|
}
|
|
}
|