diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-04-26 21:54:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-26 21:54:09 -0700 |
| commit | 400c8ef8d88eae27a1abbef3da0badd8ef1bab6d (patch) | |
| tree | 621d6f4f432cefe75c455939e084193eb7462001 /weed/util/bytes_test.go | |
| parent | 86185262bb86e31f9a2f71e85d02df2502c7ad40 (diff) | |
| parent | cf552417a7a422d1313c53972fd1175684e758e0 (diff) | |
| download | seaweedfs-400c8ef8d88eae27a1abbef3da0badd8ef1bab6d.tar.xz seaweedfs-400c8ef8d88eae27a1abbef3da0badd8ef1bab6d.zip | |
Merge pull request #2025 from bingoohuang/master
improvement for minFreeSpace argument
Diffstat (limited to 'weed/util/bytes_test.go')
| -rw-r--r-- | weed/util/bytes_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/weed/util/bytes_test.go b/weed/util/bytes_test.go new file mode 100644 index 000000000..d9269cadb --- /dev/null +++ b/weed/util/bytes_test.go @@ -0,0 +1,59 @@ +package util + +import "testing" + +func TestByteParsing(t *testing.T) { + tests := []struct { + in string + exp uint64 + }{ + {"42", 42}, + {"42MB", 42000000}, + {"42MiB", 44040192}, + {"42mb", 42000000}, + {"42mib", 44040192}, + {"42MIB", 44040192}, + {"42 MB", 42000000}, + {"42 MiB", 44040192}, + {"42 mb", 42000000}, + {"42 mib", 44040192}, + {"42 MIB", 44040192}, + {"42.5MB", 42500000}, + {"42.5MiB", 44564480}, + {"42.5 MB", 42500000}, + {"42.5 MiB", 44564480}, + // No need to say B + {"42M", 42000000}, + {"42Mi", 44040192}, + {"42m", 42000000}, + {"42mi", 44040192}, + {"42MI", 44040192}, + {"42 M", 42000000}, + {"42 Mi", 44040192}, + {"42 m", 42000000}, + {"42 mi", 44040192}, + {"42 MI", 44040192}, + {"42.5M", 42500000}, + {"42.5Mi", 44564480}, + {"42.5 M", 42500000}, + {"42.5 Mi", 44564480}, + // Bug #42 + {"1,005.03 MB", 1005030000}, + // Large testing, breaks when too much larger than + // this. + {"12.5 EB", uint64(12.5 * float64(EByte))}, + {"12.5 E", uint64(12.5 * float64(EByte))}, + {"12.5 EiB", uint64(12.5 * float64(EiByte))}, + } + + for _, p := range tests { + got, err := ParseBytes(p.in) + if err != nil { + t.Errorf("Couldn't parse %v: %v", p.in, err) + } + if got != p.exp { + t.Errorf("Expected %v for %v, got %v", + p.exp, p.in, got) + } + } +} |
