[MM-19165] Migrate tests from "model/utils_test.go" to use tes… (#12610)

Этот коммит содержится в:
Karan Nadagoudar
2019-10-05 11:31:50 +05:30
коммит произвёл Ben Schumacher
родитель 51b5776fd0
Коммит cbb25838a6

Просмотреть файл

@@ -18,18 +18,14 @@ import (
func TestNewId(t *testing.T) {
for i := 0; i < 1000; i++ {
id := NewId()
if len(id) > 26 {
t.Fatal("ids shouldn't be longer than 26 chars")
}
require.LessOrEqual(t, len(id), 26, "ids shouldn't be longer than 26 chars")
}
}
func TestRandomString(t *testing.T) {
for i := 0; i < 1000; i++ {
r := NewRandomString(32)
if len(r) != 32 {
t.Fatal("should be 32 chars")
}
require.Len(t, r, 32)
}
}
@@ -39,9 +35,7 @@ func TestGetMillisForTime(t *testing.T) {
result := GetMillisForTime(thisTime)
if thisTimeMillis != result {
t.Fatalf(fmt.Sprintf("millis are not the same: %d and %d", thisTimeMillis, result))
}
require.Equalf(t, thisTimeMillis, result, "millis are not the same: %d and %d", thisTimeMillis, result)
}
func TestPadDateStringZeros(t *testing.T) {
@@ -100,14 +94,10 @@ func TestMapJson(t *testing.T) {
rm := MapFromJson(strings.NewReader(json))
if rm["id"] != "test_id" {
t.Fatal("map should be valid")
}
require.Equal(t, rm["id"], "test_id", "map should be valid")
rm2 := MapFromJson(strings.NewReader(""))
if len(rm2) > 0 {
t.Fatal("make should be ivalid")
}
require.LessOrEqual(t, len(rm2), 0, "make should be ivalid")
}
func TestIsValidEmail(t *testing.T) {
@@ -295,9 +285,8 @@ func TestStringArray_Equal(t *testing.T) {
func TestParseHashtags(t *testing.T) {
for input, output := range hashtags {
if o, _ := ParseHashtags(input); o != output {
t.Fatal("failed to parse hashtags from input=" + input + " expected=" + output + " actual=" + o)
}
o, _ := ParseHashtags(input)
require.Equal(t, o, output, "failed to parse hashtags from input="+input+" expected="+output+" actual="+o)
}
}
@@ -350,16 +339,12 @@ func TestIsValidAlphaNum(t *testing.T) {
for _, tc := range cases {
actual := IsValidAlphaNum(tc.Input)
if actual != tc.Result {
t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
}
require.Equalf(t, actual, tc.Result, "case: %v\tshould returned: %#v", tc, tc.Result)
}
}
func TestGetServerIpAddress(t *testing.T) {
if len(GetServerIpAddress("")) == 0 {
t.Fatal("Should find local ip address")
}
require.NotEmpty(t, GetServerIpAddress(""), "Should find local ip address")
}
func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
@@ -419,9 +404,7 @@ func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
for _, tc := range casesWithFormat {
actual := IsValidAlphaNumHyphenUnderscore(tc.Input, true)
if actual != tc.Result {
t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
}
require.Equalf(t, actual, tc.Result, "case: %v\tshould returned: %#v", tc, tc.Result)
}
casesWithoutFormat := []struct {
@@ -489,9 +472,7 @@ func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
for _, tc := range casesWithoutFormat {
actual := IsValidAlphaNumHyphenUnderscore(tc.Input, false)
if actual != tc.Result {
t.Fatalf("case: '%v'\tshould returned: %#v", tc.Input, tc.Result)
}
require.Equalf(t, actual, tc.Result, "case: '%v'\tshould returned: %#v", tc.Input, tc.Result)
}
}
@@ -524,9 +505,7 @@ func TestIsValidId(t *testing.T) {
for _, tc := range cases {
actual := IsValidId(tc.Input)
if actual != tc.Result {
t.Fatalf("case: %v\tshould returned: %#v", tc, tc.Result)
}
require.Equalf(t, actual, tc.Result, "case: %v\tshould returned: %#v", tc, tc.Result)
}
}