refactor: make internals easier to test and add unit tests #2

Merged
Emmanuel BENOîT merged 13 commits from tseeker/gomonop:20240719-more-tests into master 2024-07-20 10:01:05 +02:00
Showing only changes of commit cf88d63bc2 - Show all commits

View file

@ -3,7 +3,6 @@
package perfdata // import nocternity.net/gomonop/pkg/perfdata
import (
"fmt"
"strings"
)
@ -70,26 +69,28 @@ func (d *PerfData) String() string {
var strBuilder strings.Builder
needsQuotes := strings.ContainsAny(d.Label, " '=\"")
if needsQuotes {
strBuilder.WriteString("'")
strBuilder.WriteRune('\'')
}
strBuilder.WriteString(strings.ReplaceAll(d.Label, "'", "''"))
if needsQuotes {
strBuilder.WriteString("'")
strBuilder.WriteRune('\'')
}
strBuilder.WriteString("=")
strBuilder.WriteString(fmt.Sprintf("%s%s;", d.value, d.units.String()))
strBuilder.WriteRune('=')
strBuilder.WriteString(d.value)
strBuilder.WriteString(d.units.String())
strBuilder.WriteRune(';')
if d.bits&PDatWarn != 0 {
strBuilder.WriteString(d.warn.String())
}
strBuilder.WriteString(";")
strBuilder.WriteRune(';')
if d.bits&PDatCrit != 0 {
strBuilder.WriteString(d.crit.String())
}
strBuilder.WriteString(";")
strBuilder.WriteRune(';')
if d.bits&PDatMin != 0 {
strBuilder.WriteString(d.min)
}
strBuilder.WriteString(";")
strBuilder.WriteRune(';')
if d.bits&PDatMax != 0 {
strBuilder.WriteString(d.max)
}