Tests: Change util GoConvey tests to use testify (#26724)

This commit is contained in:
Emil Tullstedt
2020-08-13 11:10:48 +02:00
committed by GitHub
parent 3bed3248d9
commit d664853179
7 changed files with 297 additions and 253 deletions

View File

@@ -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))
})
}
}