summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Loibl <mail@matthiasloibl.com>2016-11-07 00:32:32 +0100
committerMatthias Loibl <mail@matthiasloibl.com>2016-11-07 23:29:42 +0100
commitd874a9bf6b57f3d211ab1e0a07a47b7cad18a62f (patch)
tree9d036b74a41969ed9fb89e47062a9b1376ffc84d
parent11c9160cd32934bc94e3c8bbfaeded577b1ebccb (diff)
downloadgitea-d874a9bf6b57f3d211ab1e0a07a47b7cad18a62f.tar.gz
gitea-d874a9bf6b57f3d211ab1e0a07a47b7cad18a62f.zip
Add unit test for base.FileSize()
-rw-r--r--modules/base/tool_test.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index c8ed85fdeb..e92786b35b 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -1,6 +1,9 @@
package base
-import "testing"
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
func TestEncodeMD5(t *testing.T) {
if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" {
@@ -70,7 +73,25 @@ func TestHashEmail(t *testing.T) {
// TODO: TimeSince()
// TODO: logn()
// TODO: humanateBytes()
-// TODO: FileSize()
+
+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))
+}
+
// TODO: Subtract()
// TODO: EllipsisString()
// TODO: TruncateString()