From 70fb1cf9d1c72f314be2b77354afcc65aa68aea8 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 7 Nov 2016 20:28:03 +0100 Subject: [PATCH] Use testify/assert for all tests in tool_test.go --- modules/base/tool_test.go | 43 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index e92786b35b..90b94a8308 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -6,53 +6,35 @@ import ( ) func TestEncodeMD5(t *testing.T) { - if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" { - t.Errorf("got the wrong md5sum for string foobar: %s", checksum) - } - + assert.Equal(t, "3858f62230ac3c915f300c664312c63f", EncodeMD5("foobar")) } func TestEncodeSha1(t *testing.T) { - if checksum := EncodeSha1("foobar"); checksum != "8843d7f92416211de9ebb963ff4ce28125932878" { - t.Errorf("got the wrong sha1sum for string foobar: %s", checksum) - } + assert.Equal(t, "8843d7f92416211de9ebb963ff4ce28125932878", EncodeSha1("foobar")) } func TestShortSha(t *testing.T) { - if result := ShortSha("veryverylong"); result != "veryverylo" { - t.Errorf("got the wrong sha1sum for string foobar: %s", result) - } + assert.Equal(t, "veryverylo", ShortSha("veryverylong")) } // TODO: Test DetectEncoding() func TestBasicAuthDecode(t *testing.T) { - if _, _, err := BasicAuthDecode("?"); err.Error() != "illegal base64 data at input byte 0" { - t.Errorf("BasicAuthDecode should fail due to illeagl data: %v", err) - } + _, _, err := BasicAuthDecode("?") + assert.Equal(t, "illegal base64 data at input byte 0", err.Error()) user, pass, err := BasicAuthDecode("Zm9vOmJhcg==") - if err != nil { - t.Errorf("err should be nil but is: %v", err) - } - if user != "foo" { - t.Errorf("user should be foo but is: %s", user) - } - if pass != "bar" { - t.Errorf("pass should be foo but is: %s", pass) - } + assert.NoError(t, err) + assert.Equal(t, "foo", user) + assert.Equal(t, "bar", pass) } func TestBasicAuthEncode(t *testing.T) { - if auth := BasicAuthEncode("foo", "bar"); auth != "Zm9vOmJhcg==" { - t.Errorf("auth should be Zm9vOmJhcg== but is: %s", auth) - } + assert.Equal(t, "Zm9vOmJhcg==", BasicAuthEncode("foo", "bar")) } func TestGetRandomString(t *testing.T) { - if len(GetRandomString(4)) != 4 { - t.Error("expected GetRandomString to be of len 4") - } + assert.Len(t, GetRandomString(4), 4) } // TODO: Test PBKDF2() @@ -60,9 +42,8 @@ func TestGetRandomString(t *testing.T) { // TODO: Test CreateTimeLimitCode() func TestHashEmail(t *testing.T) { - if hash := HashEmail("lunny@gitea.io"); hash != "1b6d0c0e124d47ded12cd7115addeb11" { - t.Errorf("unexpected email hash: %s", hash) - } + assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", HashEmail("")) + assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", HashEmail("gitea@example.com")) } // TODO: AvatarLink()