aboutsummaryrefslogtreecommitdiff
path: root/weed/util/minfreespace_test.go
diff options
context:
space:
mode:
authorbingoohuang <bingoo.huang@gmail.com>2021-04-27 10:37:24 +0800
committerbingoohuang <bingoo.huang@gmail.com>2021-04-27 10:37:24 +0800
commitcf552417a7a422d1313c53972fd1175684e758e0 (patch)
tree621d6f4f432cefe75c455939e084193eb7462001 /weed/util/minfreespace_test.go
parent31f1cdeac281fb88a3d03743f9796f81e1d74378 (diff)
downloadseaweedfs-cf552417a7a422d1313c53972fd1175684e758e0.tar.xz
seaweedfs-cf552417a7a422d1313c53972fd1175684e758e0.zip
minFreeSpace refactored
Diffstat (limited to 'weed/util/minfreespace_test.go')
-rw-r--r--weed/util/minfreespace_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/weed/util/minfreespace_test.go b/weed/util/minfreespace_test.go
new file mode 100644
index 000000000..eec1942dd
--- /dev/null
+++ b/weed/util/minfreespace_test.go
@@ -0,0 +1,29 @@
+package util
+
+import "testing"
+
+func TestParseMinFreeSpace(t *testing.T) {
+ tests := []struct {
+ in string
+ ok bool
+ value *MinFreeSpace
+ }{
+ {in: "42", ok: true, value: &MinFreeSpace{Type: AsPercent, Percent: 42, Raw: "42"}},
+ {in: "-1", ok: false, value: nil},
+ {in: "101", ok: false, value: nil},
+ {in: "100B", ok: false, value: nil},
+ {in: "100Ki", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 100 * 1024, Raw: "100Ki"}},
+ {in: "100GiB", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 100 * 1024 * 1024 * 1024, Raw: "100GiB"}},
+ {in: "42M", ok: true, value: &MinFreeSpace{Type: AsBytes, Bytes: 42 * 1000 * 1000, Raw: "42M"}},
+ }
+
+ for _, p := range tests {
+ got, err := ParseMinFreeSpace(p.in)
+ if p.ok != (err == nil) {
+ t.Errorf("failed to test %v", p.in)
+ }
+ if p.ok && err == nil && *got != *p.value {
+ t.Errorf("failed to test %v", p.in)
+ }
+ }
+}