From cbb25838a61872b624ac512556d7bc932486a64c Mon Sep 17 00:00:00 2001 From: Karan Nadagoudar Date: Sat, 5 Oct 2019 11:31:50 +0530 Subject: [PATCH] =?UTF-8?q?[MM-19165]=20Migrate=20tests=20from=20"model/ut?= =?UTF-8?q?ils=5Ftest.go"=20to=20use=20tes=E2=80=A6=20(#12610)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/utils_test.go | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/model/utils_test.go b/model/utils_test.go index 22dc72859a..e3967f5b86 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -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) } }