Add unit test for base.FileSize()

This commit is contained in:
Matthias Loibl 2016-11-07 00:32:32 +01:00
parent 11c9160cd3
commit d874a9bf6b
No known key found for this signature in database
GPG Key ID: B1C7DF661ABB2C1A
1 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,9 @@
package base package base
import "testing" import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestEncodeMD5(t *testing.T) { func TestEncodeMD5(t *testing.T) {
if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" { if checksum := EncodeMD5("foobar"); checksum != "3858f62230ac3c915f300c664312c63f" {
@ -70,7 +73,25 @@ func TestHashEmail(t *testing.T) {
// TODO: TimeSince() // TODO: TimeSince()
// TODO: logn() // TODO: logn()
// TODO: humanateBytes() // 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: Subtract()
// TODO: EllipsisString() // TODO: EllipsisString()
// TODO: TruncateString() // TODO: TruncateString()