mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tests: Change util GoConvey tests to use testify (#26724)
This commit is contained in:
@@ -1,21 +1,38 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsEmail(t *testing.T) {
|
||||
Convey("When validating a string that is a valid email", t, func() {
|
||||
result := IsEmail("abc@def.com")
|
||||
t.Parallel()
|
||||
|
||||
So(result, ShouldEqual, true)
|
||||
})
|
||||
emails := map[string]struct {
|
||||
description string
|
||||
valid bool
|
||||
}{
|
||||
"": {description: "the empty string", valid: false},
|
||||
"@.": {description: "at dot", valid: false},
|
||||
"me@": {description: "no domain", valid: false},
|
||||
"abcdef.com": {description: "only a domain name", valid: false},
|
||||
"@example.org": {description: "no recipient", valid: false},
|
||||
"please\x0Ano@example.org": {description: "new line", valid: false},
|
||||
|
||||
Convey("When validating a string that is not a valid email", t, func() {
|
||||
result := IsEmail("abcdef.com")
|
||||
"abc@def.com": {description: "a simple valid email", valid: true},
|
||||
"grapher+grafana@example.org": {description: "a gmail style alias", valid: true},
|
||||
"öhnej@example.se": {description: "non-ASCII characters", valid: true},
|
||||
}
|
||||
for input, testcase := range emails {
|
||||
validity := "invalid"
|
||||
if testcase.valid {
|
||||
validity = "valid"
|
||||
}
|
||||
|
||||
So(result, ShouldEqual, false)
|
||||
})
|
||||
t.Run(fmt.Sprintf("validating that %s is %s", testcase.description, validity), func(t *testing.T) {
|
||||
assert.Equal(t, testcase.valid, IsEmail(input))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user