mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
30 lines
894 B
Go
30 lines
894 B
Go
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)
|
|
}
|
|
}
|
|
}
|