mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Strip ANSI color codes from notifications (#2508)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
25
pkg/notifications/notifications_test.go
Normal file
25
pkg/notifications/notifications_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user