dnscontrol/pkg/notifications/notifications_test.go
Costas Drogos 8bf996bb8e
Strip ANSI color codes from notifications (#2508)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
2023-08-29 13:24:09 -04:00

25 lines
633 B
Go

package notifications
import "testing"
func Test_stripAnsiColorsValid(t *testing.T) {
coloredStr := "\x1b[0133myellow\x1b[0m" // 33 == yellow
nonColoredStr := "yellow"
s := stripAnsiColors(coloredStr)
if s != nonColoredStr {
t.Errorf("stripAnsiColors() stripped %q different from %q", coloredStr, nonColoredStr)
}
}
func Test_stripAnsiColorsInvalid(t *testing.T) {
coloredStr := "\x1b[01AAmyellow\x1b[0m" // AA not a real color
nonColoredStr := "yellow"
s := stripAnsiColors(coloredStr)
if s == nonColoredStr {
t.Errorf("stripAnsiColors() stripped %q should be different from %q", coloredStr, nonColoredStr)
}
}