summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorMatthias Loibl <mail@matthiasloibl.com>2016-11-07 20:28:03 +0100
committerMatthias Loibl <mail@matthiasloibl.com>2016-11-07 23:29:42 +0100
commit70fb1cf9d1c72f314be2b77354afcc65aa68aea8 (patch)
treebd262715aa029d0eeec71a22724ae159fbc41720 /modules/base
parentd874a9bf6b57f3d211ab1e0a07a47b7cad18a62f (diff)
downloadgitea-70fb1cf9d1c72f314be2b77354afcc65aa68aea8.tar.gz
gitea-70fb1cf9d1c72f314be2b77354afcc65aa68aea8.zip
Use testify/assert for all tests in tool_test.go
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool_test.go43
1 files 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()