Use testify/assert for all tests in tool_test.go
This commit is contained in:
parent
d874a9bf6b
commit
70fb1cf9d1
|
@ -6,53 +6,35 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncodeMD5(t *testing.T) {
|
func TestEncodeMD5(t *testing.T) {
|
||||||
if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" {
|
assert.Equal(t, "3858f62230ac3c915f300c664312c63f", EncodeMD5("foobar"))
|
||||||
t.Errorf("got the wrong md5sum for string foobar: %s", checksum)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncodeSha1(t *testing.T) {
|
func TestEncodeSha1(t *testing.T) {
|
||||||
if checksum := EncodeSha1("foobar"); checksum != "8843d7f92416211de9ebb963ff4ce28125932878" {
|
assert.Equal(t, "8843d7f92416211de9ebb963ff4ce28125932878", EncodeSha1("foobar"))
|
||||||
t.Errorf("got the wrong sha1sum for string foobar: %s", checksum)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShortSha(t *testing.T) {
|
func TestShortSha(t *testing.T) {
|
||||||
if result := ShortSha("veryverylong"); result != "veryverylo" {
|
assert.Equal(t, "veryverylo", ShortSha("veryverylong"))
|
||||||
t.Errorf("got the wrong sha1sum for string foobar: %s", result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test DetectEncoding()
|
// TODO: Test DetectEncoding()
|
||||||
|
|
||||||
func TestBasicAuthDecode(t *testing.T) {
|
func TestBasicAuthDecode(t *testing.T) {
|
||||||
if _, _, err := BasicAuthDecode("?"); err.Error() != "illegal base64 data at input byte 0" {
|
_, _, err := BasicAuthDecode("?")
|
||||||
t.Errorf("BasicAuthDecode should fail due to illeagl data: %v", err)
|
assert.Equal(t, "illegal base64 data at input byte 0", err.Error())
|
||||||
}
|
|
||||||
|
|
||||||
user, pass, err := BasicAuthDecode("Zm9vOmJhcg==")
|
user, pass, err := BasicAuthDecode("Zm9vOmJhcg==")
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Errorf("err should be nil but is: %v", err)
|
assert.Equal(t, "foo", user)
|
||||||
}
|
assert.Equal(t, "bar", pass)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBasicAuthEncode(t *testing.T) {
|
func TestBasicAuthEncode(t *testing.T) {
|
||||||
if auth := BasicAuthEncode("foo", "bar"); auth != "Zm9vOmJhcg==" {
|
assert.Equal(t, "Zm9vOmJhcg==", BasicAuthEncode("foo", "bar"))
|
||||||
t.Errorf("auth should be Zm9vOmJhcg== but is: %s", auth)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRandomString(t *testing.T) {
|
func TestGetRandomString(t *testing.T) {
|
||||||
if len(GetRandomString(4)) != 4 {
|
assert.Len(t, GetRandomString(4), 4)
|
||||||
t.Error("expected GetRandomString to be of len 4")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test PBKDF2()
|
// TODO: Test PBKDF2()
|
||||||
|
@ -60,9 +42,8 @@ func TestGetRandomString(t *testing.T) {
|
||||||
// TODO: Test CreateTimeLimitCode()
|
// TODO: Test CreateTimeLimitCode()
|
||||||
|
|
||||||
func TestHashEmail(t *testing.T) {
|
func TestHashEmail(t *testing.T) {
|
||||||
if hash := HashEmail("lunny@gitea.io"); hash != "1b6d0c0e124d47ded12cd7115addeb11" {
|
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", HashEmail(""))
|
||||||
t.Errorf("unexpected email hash: %s", hash)
|
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", HashEmail("gitea@example.com"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: AvatarLink()
|
// TODO: AvatarLink()
|
||||||
|
|
Loading…
Reference in New Issue