You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tool_test.go 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package base
  2. import "testing"
  3. func TestEncodeMD5(t *testing.T) {
  4. if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" {
  5. t.Errorf("got the wrong md5sum for string foobar: %s", checksum)
  6. }
  7. }
  8. func TestEncodeSha1(t *testing.T) {
  9. if checksum := EncodeSha1("foobar"); checksum != "8843d7f92416211de9ebb963ff4ce28125932878" {
  10. t.Errorf("got the wrong sha1sum for string foobar: %s", checksum)
  11. }
  12. }
  13. func TestShortSha(t *testing.T) {
  14. if result := ShortSha("veryverylong"); result != "veryverylo" {
  15. t.Errorf("got the wrong sha1sum for string foobar: %s", result)
  16. }
  17. }
  18. // TODO: Test DetectEncoding()
  19. func TestBasicAuthDecode(t *testing.T) {
  20. if _, _, err := BasicAuthDecode("?"); err.Error() != "illegal base64 data at input byte 0" {
  21. t.Errorf("BasicAuthDecode should fail due to illeagl data: %v", err)
  22. }
  23. user, pass, err := BasicAuthDecode("Zm9vOmJhcg==")
  24. if err != nil {
  25. t.Errorf("err should be nil but is: %v", err)
  26. }
  27. if user != "foo" {
  28. t.Errorf("user should be foo but is: %s", user)
  29. }
  30. if pass != "bar" {
  31. t.Errorf("pass should be foo but is: %s", pass)
  32. }
  33. }
  34. func TestBasicAuthEncode(t *testing.T) {
  35. if auth := BasicAuthEncode("foo", "bar"); auth != "Zm9vOmJhcg==" {
  36. t.Errorf("auth should be Zm9vOmJhcg== but is: %s", auth)
  37. }
  38. }
  39. func TestGetRandomString(t *testing.T) {
  40. if len(GetRandomString(4)) != 4 {
  41. t.Error("expected GetRandomString to be of len 4")
  42. }
  43. }
  44. // TODO: Test PBKDF2()
  45. // TODO: Test VerifyTimeLimitCode()
  46. // TODO: Test CreateTimeLimitCode()
  47. func TestHashEmail(t *testing.T) {
  48. if hash := HashEmail("lunny@gitea.io"); hash != "1b6d0c0e124d47ded12cd7115addeb11" {
  49. t.Errorf("unexpected email hash: %s", hash)
  50. }
  51. }
  52. // TODO: AvatarLink()
  53. // TODO: computeTimeDiff()
  54. // TODO: TimeSincePro()
  55. // TODO: timeSince()
  56. // TODO: RawTimeSince()
  57. // TODO: TimeSince()
  58. // TODO: logn()
  59. // TODO: humanateBytes()
  60. // TODO: FileSize()
  61. // TODO: Subtract()
  62. // TODO: EllipsisString()
  63. // TODO: TruncateString()
  64. // TODO: StringsToInt64s()
  65. // TODO: Int64sToStrings()
  66. // TODO: Int64sToMap()
  67. // TODO: IsLetter()
  68. // TODO: IsTextFile()
  69. // TODO: IsImageFile()
  70. // TODO: IsPDFFile()