2016-11-05 19:53:11 -05:00
|
|
|
package base
|
|
|
|
|
2016-11-06 18:32:32 -05:00
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
2016-11-05 19:53:11 -05:00
|
|
|
|
|
|
|
func TestEncodeMD5(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Equal(t, "3858f62230ac3c915f300c664312c63f", EncodeMD5("foobar"))
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEncodeSha1(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Equal(t, "8843d7f92416211de9ebb963ff4ce28125932878", EncodeSha1("foobar"))
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestShortSha(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Equal(t, "veryverylo", ShortSha("veryverylong"))
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Test DetectEncoding()
|
|
|
|
|
|
|
|
func TestBasicAuthDecode(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
_, _, err := BasicAuthDecode("?")
|
|
|
|
assert.Equal(t, "illegal base64 data at input byte 0", err.Error())
|
2016-11-05 19:53:11 -05:00
|
|
|
|
|
|
|
user, pass, err := BasicAuthDecode("Zm9vOmJhcg==")
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "foo", user)
|
|
|
|
assert.Equal(t, "bar", pass)
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasicAuthEncode(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Equal(t, "Zm9vOmJhcg==", BasicAuthEncode("foo", "bar"))
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRandomString(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Len(t, GetRandomString(4), 4)
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Test PBKDF2()
|
|
|
|
// TODO: Test VerifyTimeLimitCode()
|
|
|
|
// TODO: Test CreateTimeLimitCode()
|
|
|
|
|
|
|
|
func TestHashEmail(t *testing.T) {
|
2016-11-07 14:28:03 -05:00
|
|
|
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", HashEmail(""))
|
|
|
|
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", HashEmail("gitea@example.com"))
|
2016-11-05 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: AvatarLink()
|
|
|
|
// TODO: computeTimeDiff()
|
|
|
|
// TODO: TimeSincePro()
|
|
|
|
// TODO: timeSince()
|
|
|
|
// TODO: RawTimeSince()
|
|
|
|
// TODO: TimeSince()
|
|
|
|
// TODO: logn()
|
|
|
|
// TODO: humanateBytes()
|
2016-11-06 18:32:32 -05:00
|
|
|
|
|
|
|
func TestFileSize(t *testing.T) {
|
|
|
|
var size int64
|
|
|
|
size = 512
|
|
|
|
assert.Equal(t, "512B", FileSize(size))
|
|
|
|
size = size * 1024
|
|
|
|
assert.Equal(t, "512KB", FileSize(size))
|
|
|
|
size = size * 1024
|
|
|
|
assert.Equal(t, "512MB", FileSize(size))
|
|
|
|
size = size * 1024
|
|
|
|
assert.Equal(t, "512GB", FileSize(size))
|
|
|
|
size = size * 1024
|
|
|
|
assert.Equal(t, "512TB", FileSize(size))
|
|
|
|
size = size * 1024
|
|
|
|
assert.Equal(t, "512PB", FileSize(size))
|
|
|
|
//size = size * 1024 TODO: Fix bug for EB
|
|
|
|
//assert.Equal(t, "512EB", FileSize(size))
|
|
|
|
}
|
|
|
|
|
2016-11-05 19:53:11 -05:00
|
|
|
// TODO: Subtract()
|
|
|
|
// TODO: EllipsisString()
|
|
|
|
// TODO: TruncateString()
|
|
|
|
// TODO: StringsToInt64s()
|
|
|
|
// TODO: Int64sToStrings()
|
|
|
|
// TODO: Int64sToMap()
|
|
|
|
// TODO: IsLetter()
|
|
|
|
// TODO: IsTextFile()
|
|
|
|
// TODO: IsImageFile()
|
|
|
|
// TODO: IsPDFFile()
|