Use testify/assert for all tests in tool_test.go

release/v1.15
Matthias Loibl 2016-11-07 20:28:03 +01:00
parent d874a9bf6b
commit 70fb1cf9d1
No known key found for this signature in database
GPG Key ID: B1C7DF661ABB2C1A
1 changed files with 12 additions and 31 deletions

View File

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